diff --git a/lib/liquid/lexer.rb b/lib/liquid/lexer.rb index 6d956484b..61ee24a9d 100644 --- a/lib/liquid/lexer.rb +++ b/lib/liquid/lexer.rb @@ -73,7 +73,6 @@ class Lexer2 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 @@ def tokenize 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] diff --git a/test/unit/lexer_unit_test.rb b/test/unit/lexer_unit_test.rb index b372c232e..5aa6066fa 100644 --- a/test/unit/lexer_unit_test.rb +++ b/test/unit/lexer_unit_test.rb @@ -95,4 +95,11 @@ def test_error_with_utf8_character 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