mirror of
https://github.com/kemko/liquid.git
synced 2026-01-04 01:05:40 +03:00
A better fix for "and"/"or" in strings
(now with less side effects)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user