A better fix for "and"/"or" in strings

(now with less side effects)
This commit is contained in:
James MacAulay
2009-09-23 15:44:29 -04:00
parent f42ce88456
commit 11dc18bfdf
4 changed files with 22 additions and 15 deletions

View File

@@ -21,10 +21,6 @@ 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

View File

@@ -13,8 +13,8 @@ module Liquid
#
class If < Block
SyntaxHelp = "Syntax Error in tag 'if' - Valid syntax: if [expression]"
Syntax = /(#{QuotedFragment})\s*(?:([=!<>a-z_]+)\s*(#{QuotedFragment}))?/
ExpressionsAndOperators = /and|or|#{QuotedFragment}\s*(?:(?!and|or)(?:[=!<>a-z_]+)\s*#{QuotedFragment})?/
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/
ExpressionsAndOperators = /(?:and|or|(?:\s*(?!\b(?:and|or)\b)(?:#{QuotedFragment}|\S+)\s*)+)/
def initialize(tag_name, markup, tokens)
@@ -51,9 +51,7 @@ module Liquid
ElseCondition.new
else
# expressions = markup.split(/\b(and|or)\b/).reverse
expressions = markup.scan(ExpressionsAndOperators).flatten.compact.reverse
expressions = markup.scan(ExpressionsAndOperators).reverse
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
condition = Condition.new($1, $2, $3)