fixed conditions with strings containing "and"/"or"

This commit is contained in:
James MacAulay
2009-09-14 15:01:26 -04:00
parent d1d6febfc1
commit f42ce88456
4 changed files with 23 additions and 8 deletions
+4
View File
@@ -21,6 +21,10 @@ module Liquid
def self.operators
@@operators
end
def self.operator_regexp
Regexp.new(@@operators.keys.sort_by(&:length).reverse.map {|k| Regexp.escape(k)}.join('|'))
end
attr_reader :attachment
attr_accessor :left, :operator, :right
+5 -2
View File
@@ -13,7 +13,8 @@ module Liquid
#
class If < Block
SyntaxHelp = "Syntax Error in tag 'if' - Valid syntax: if [expression]"
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/
Syntax = /(#{QuotedFragment})\s*(?:([=!<>a-z_]+)\s*(#{QuotedFragment}))?/
ExpressionsAndOperators = /and|or|#{QuotedFragment}\s*(?:(?!and|or)(?:[=!<>a-z_]+)\s*#{QuotedFragment})?/
def initialize(tag_name, markup, tokens)
@@ -50,7 +51,9 @@ module Liquid
ElseCondition.new
else
expressions = markup.split(/\b(and|or)\b/).reverse
# expressions = markup.split(/\b(and|or)\b/).reverse
expressions = markup.scan(ExpressionsAndOperators).flatten.compact.reverse
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
condition = Condition.new($1, $2, $3)