Skip to content

Commit

Permalink
avoid using StringScanner eos
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Oct 30, 2024
1 parent f00670c commit ffce6de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/liquid/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def tokenize
@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
Expand All @@ -192,15 +192,15 @@ def tokenize
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
raise_syntax_error(start_pos)
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
Expand Down
4 changes: 2 additions & 2 deletions test/unit/lexer_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_greater_than_two_digits

def test_error_with_utf8_character
error = assert_raises(SyntaxError) do
Lexer.new("1 < 1Ø").tokenize
tokenize("1 < 1Ø")
end

assert_equal(
Expand All @@ -120,7 +120,7 @@ def test_error_with_utf8_character
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

Expand Down

0 comments on commit ffce6de

Please sign in to comment.