diff --git a/lib/liquid/lexer.rb b/lib/liquid/lexer.rb index d02c24e6..b9e5443c 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 !@ss.eos? && NUMBER_TABLE[@ss.peek_byte] + if (peeked_byte = @ss.peek_byte) && NUMBER_TABLE[peeked_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 !@ss.eos? && (found = sub_table[@ss.peek_byte]) + if (peeked_byte = @ss.peek_byte) && (found = sub_table[peeked_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 !@ss.eos? && (found = sub_table[@ss.peek_byte]) + if (peeked_byte = @ss.peek_byte) && (found = sub_table[peeked_byte]) @output << found @ss.scan_byte else diff --git a/test/unit/lexer_unit_test.rb b/test/unit/lexer_unit_test.rb index 7f845739..26a25b62 100644 --- a/test/unit/lexer_unit_test.rb +++ b/test/unit/lexer_unit_test.rb @@ -108,7 +108,7 @@ class LexerUnitTest < Minitest::Test def test_error_with_utf8_character error = assert_raises(SyntaxError) do - Lexer.new("1 < 1Ø").tokenize + tokenize("1 < 1Ø") end assert_equal( @@ -120,7 +120,7 @@ class LexerUnitTest < Minitest::Test 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, + tokenize("a.contains.b"), ) end