diff --git a/lib/liquid/lexer.rb b/lib/liquid/lexer.rb index 61ee24a9..d02c24e6 100644 --- a/lib/liquid/lexer.rb +++ b/lib/liquid/lexer.rb @@ -181,7 +181,7 @@ module Liquid @output << DOTDOT elsif special == DASH # Special case for negative numbers - if NUMBER_TABLE[@ss.peek_byte] + if !@ss.eos? && NUMBER_TABLE[@ss.peek_byte] @ss.pos -= 1 @output << [:number, @ss.scan(NUMBER_LITERAL)] else @@ -192,7 +192,7 @@ module Liquid end elsif (sub_table = TWO_CHARS_COMPARISON_JUMP_TABLE[peeked]) @ss.scan_byte - if (found = sub_table[@ss.peek_byte]) + if !@ss.eos? && (found = sub_table[@ss.peek_byte]) @output << found @ss.scan_byte else @@ -200,7 +200,7 @@ module Liquid end elsif (sub_table = COMPARISON_JUMP_TABLE[peeked]) @ss.scan_byte - if (found = sub_table[@ss.peek_byte]) + if !@ss.eos? && (found = sub_table[@ss.peek_byte]) @output << found @ss.scan_byte else diff --git a/test/integration/parsing_quirks_test.rb b/test/integration/parsing_quirks_test.rb index 744936c9..48f91463 100644 --- a/test/integration/parsing_quirks_test.rb +++ b/test/integration/parsing_quirks_test.rb @@ -131,4 +131,16 @@ class ParsingQuirksTest < Minitest::Test def test_contains_in_id assert_template_result(' YES ', '{% if containsallshipments == true %} YES {% endif %}', { 'containsallshipments' => true }) end + + def test_incomplete_expression + with_error_mode(:lax) do + assert_template_result("false", "{% liquid assign foo = false -\n%}{{ foo }}") + assert_template_result("false", "{% liquid assign foo = false >\n%}{{ foo }}") + assert_template_result("false", "{% liquid assign foo = false <\n%}{{ foo }}") + assert_template_result("false", "{% liquid assign foo = false =\n%}{{ foo }}") + assert_template_result("false", "{% liquid assign foo = false !\n%}{{ foo }}") + assert_template_result("false", "{% liquid assign foo = false 1\n%}{{ foo }}") + assert_template_result("false", "{% liquid assign foo = false a\n%}{{ foo }}") + end + end end # ParsingQuirksTest diff --git a/test/unit/lexer_unit_test.rb b/test/unit/lexer_unit_test.rb index 5aa6066f..54ed0b50 100644 --- a/test/unit/lexer_unit_test.rb +++ b/test/unit/lexer_unit_test.rb @@ -102,4 +102,11 @@ class LexerUnitTest < Minitest::Test Lexer.new("a.contains.b").tokenize, ) end + + def test_tokenize_incomplete_expression + assert_equal([[:id, "false"], [:dash, "-"], [:end_of_string]], Lexer.new("false -").tokenize) + assert_equal([[:id, "false"], [:comparison, "<"], [:end_of_string]], Lexer.new("false <").tokenize) + assert_equal([[:id, "false"], [:comparison, ">"], [:end_of_string]], Lexer.new("false >").tokenize) + assert_equal([[:id, "false"], [:number, "1"], [:end_of_string]], Lexer.new("false 1").tokenize) + end end