mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 11:20:41 -07:00
Merge pull request #1840 from Shopify/fix-lexer-contains-as-id
fix lexer parsing ID 'contains' as comparison
This commit is contained in:
+1
-2
@@ -73,7 +73,6 @@ module Liquid
|
|||||||
COMPARISON_LESS_THAN = [:comparison, "<"].freeze
|
COMPARISON_LESS_THAN = [:comparison, "<"].freeze
|
||||||
COMPARISON_LESS_THAN_OR_EQUAL = [:comparison, "<="].freeze
|
COMPARISON_LESS_THAN_OR_EQUAL = [:comparison, "<="].freeze
|
||||||
COMPARISON_NOT_EQUAL_ALT = [:comparison, "<>"].freeze
|
COMPARISON_NOT_EQUAL_ALT = [:comparison, "<>"].freeze
|
||||||
CONTAINS = /contains(?=\s)/
|
|
||||||
DASH = [:dash, "-"].freeze
|
DASH = [:dash, "-"].freeze
|
||||||
DOT = [:dot, "."].freeze
|
DOT = [:dot, "."].freeze
|
||||||
DOTDOT = [:dotdot, ".."].freeze
|
DOTDOT = [:dotdot, ".."].freeze
|
||||||
@@ -212,7 +211,7 @@ module Liquid
|
|||||||
|
|
||||||
if type && (t = @ss.scan(pattern))
|
if type && (t = @ss.scan(pattern))
|
||||||
# Special case for "contains"
|
# Special case for "contains"
|
||||||
@output << if type == :id && t == "contains"
|
@output << if type == :id && t == "contains" && @output.last&.first != :dot
|
||||||
COMPARISON_CONTAINS
|
COMPARISON_CONTAINS
|
||||||
else
|
else
|
||||||
[type, t]
|
[type, t]
|
||||||
|
|||||||
@@ -95,4 +95,11 @@ class LexerUnitTest < Minitest::Test
|
|||||||
error.message,
|
error.message,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_contains_as_attribute_name
|
||||||
|
assert_equal(
|
||||||
|
[[:id, "a"], [:dot, "."], [:id, "contains"], [:dot, "."], [:id, "b"], [:end_of_string]],
|
||||||
|
Lexer.new("a.contains.b").tokenize,
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user