Merge pull request #1840 from Shopify/fix-lexer-contains-as-id

fix lexer parsing ID 'contains' as comparison
This commit is contained in:
Michael Go
2024-10-30 13:43:48 -03:00
committed by GitHub
2 changed files with 8 additions and 2 deletions
+1 -2
View File
@@ -73,7 +73,6 @@ module Liquid
COMPARISON_LESS_THAN = [:comparison, "<"].freeze
COMPARISON_LESS_THAN_OR_EQUAL = [:comparison, "<="].freeze
COMPARISON_NOT_EQUAL_ALT = [:comparison, "<>"].freeze
CONTAINS = /contains(?=\s)/
DASH = [:dash, "-"].freeze
DOT = [:dot, "."].freeze
DOTDOT = [:dotdot, ".."].freeze
@@ -212,7 +211,7 @@ module Liquid
if type && (t = @ss.scan(pattern))
# Special case for "contains"
@output << if type == :id && t == "contains"
@output << if type == :id && t == "contains" && @output.last&.first != :dot
COMPARISON_CONTAINS
else
[type, t]
+7
View File
@@ -95,4 +95,11 @@ class LexerUnitTest < Minitest::Test
error.message,
)
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