mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 07:05:12 -07:00
Merge pull request #789 from evulse/contains-strict-fix
Allow variables to start with contains in strict parser
This commit is contained in:
@@ -24,6 +24,8 @@
|
|||||||
* Liquid::Template.register_filter raises when the module overrides registered public methods as private or protected (#705) [Gaurav Chande]
|
* Liquid::Template.register_filter raises when the module overrides registered public methods as private or protected (#705) [Gaurav Chande]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
* Fix variable names being detected as an operator when starting with contains (#788) [Michael Angell]
|
||||||
* Fix include tag used with strict_variables (#828) [QuickPay]
|
* Fix include tag used with strict_variables (#828) [QuickPay]
|
||||||
* Fix map filter when value is a Proc (#672) [Guillaume Malette]
|
* Fix map filter when value is a Proc (#672) [Guillaume Malette]
|
||||||
* Fix truncate filter when value is not a string (#672) [Guillaume Malette]
|
* Fix truncate filter when value is not a string (#672) [Guillaume Malette]
|
||||||
|
|||||||
+3
-2
@@ -18,10 +18,10 @@ module Liquid
|
|||||||
DOUBLE_STRING_LITERAL = /"[^\"]*"/
|
DOUBLE_STRING_LITERAL = /"[^\"]*"/
|
||||||
NUMBER_LITERAL = /-?\d+(\.\d+)?/
|
NUMBER_LITERAL = /-?\d+(\.\d+)?/
|
||||||
DOTDOT = /\.\./
|
DOTDOT = /\.\./
|
||||||
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains/
|
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains(?=\s)/
|
||||||
|
|
||||||
def initialize(input)
|
def initialize(input)
|
||||||
@ss = StringScanner.new(input.rstrip)
|
@ss = StringScanner.new(input)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tokenize
|
def tokenize
|
||||||
@@ -29,6 +29,7 @@ module Liquid
|
|||||||
|
|
||||||
until @ss.eos?
|
until @ss.eos?
|
||||||
@ss.skip(/\s*/)
|
@ss.skip(/\s*/)
|
||||||
|
break if @ss.eos?
|
||||||
tok = case
|
tok = case
|
||||||
when t = @ss.scan(COMPARISON_OPERATOR) then [:comparison, t]
|
when t = @ss.scan(COMPARISON_OPERATOR) then [:comparison, t]
|
||||||
when t = @ss.scan(SINGLE_STRING_LITERAL) then [:string, t]
|
when t = @ss.scan(SINGLE_STRING_LITERAL) then [:string, t]
|
||||||
|
|||||||
@@ -115,4 +115,8 @@ class ParsingQuirksTest < Minitest::Test
|
|||||||
assert_template_result('12345', "{% for i in (1...5) %}{{ i }}{% endfor %}")
|
assert_template_result('12345', "{% for i in (1...5) %}{{ i }}{% endfor %}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_contains_in_id
|
||||||
|
assert_template_result(' YES ', '{% if containsallshipments == true %} YES {% endif %}', 'containsallshipments' => true)
|
||||||
|
end
|
||||||
end # ParsingQuirksTest
|
end # ParsingQuirksTest
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class LexerUnitTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_comparison
|
def test_comparison
|
||||||
tokens = Lexer.new('== <> contains').tokenize
|
tokens = Lexer.new('== <> contains ').tokenize
|
||||||
assert_equal [[:comparison, '=='], [:comparison, '<>'], [:comparison, 'contains'], [:end_of_string]], tokens
|
assert_equal [[:comparison, '=='], [:comparison, '<>'], [:comparison, 'contains'], [:end_of_string]], tokens
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user