mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 02:40:41 -07:00
fix parsing quirky incomplete expressions
This commit is contained in:
+3
-3
@@ -181,7 +181,7 @@ module Liquid
|
|||||||
@output << DOTDOT
|
@output << DOTDOT
|
||||||
elsif special == DASH
|
elsif special == DASH
|
||||||
# Special case for negative numbers
|
# Special case for negative numbers
|
||||||
if NUMBER_TABLE[@ss.peek_byte]
|
if !@ss.eos? && NUMBER_TABLE[@ss.peek_byte]
|
||||||
@ss.pos -= 1
|
@ss.pos -= 1
|
||||||
@output << [:number, @ss.scan(NUMBER_LITERAL)]
|
@output << [:number, @ss.scan(NUMBER_LITERAL)]
|
||||||
else
|
else
|
||||||
@@ -192,7 +192,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
elsif (sub_table = TWO_CHARS_COMPARISON_JUMP_TABLE[peeked])
|
elsif (sub_table = TWO_CHARS_COMPARISON_JUMP_TABLE[peeked])
|
||||||
@ss.scan_byte
|
@ss.scan_byte
|
||||||
if (found = sub_table[@ss.peek_byte])
|
if !@ss.eos? && (found = sub_table[@ss.peek_byte])
|
||||||
@output << found
|
@output << found
|
||||||
@ss.scan_byte
|
@ss.scan_byte
|
||||||
else
|
else
|
||||||
@@ -200,7 +200,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
elsif (sub_table = COMPARISON_JUMP_TABLE[peeked])
|
elsif (sub_table = COMPARISON_JUMP_TABLE[peeked])
|
||||||
@ss.scan_byte
|
@ss.scan_byte
|
||||||
if (found = sub_table[@ss.peek_byte])
|
if !@ss.eos? && (found = sub_table[@ss.peek_byte])
|
||||||
@output << found
|
@output << found
|
||||||
@ss.scan_byte
|
@ss.scan_byte
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -131,4 +131,16 @@ class ParsingQuirksTest < Minitest::Test
|
|||||||
def test_contains_in_id
|
def test_contains_in_id
|
||||||
assert_template_result(' YES ', '{% if containsallshipments == true %} YES {% endif %}', { 'containsallshipments' => true })
|
assert_template_result(' YES ', '{% if containsallshipments == true %} YES {% endif %}', { 'containsallshipments' => true })
|
||||||
end
|
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
|
end # ParsingQuirksTest
|
||||||
|
|||||||
@@ -102,4 +102,11 @@ class LexerUnitTest < Minitest::Test
|
|||||||
Lexer.new("a.contains.b").tokenize,
|
Lexer.new("a.contains.b").tokenize,
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user