mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 19:30:47 -07:00
Attempt to strict parse variables before lax parsing in lax error mode (#1338)
This commit is contained in:
@@ -2,6 +2,18 @@
|
|||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
module ParserSwitching
|
module ParserSwitching
|
||||||
|
def strict_parse_with_error_mode_fallback(markup)
|
||||||
|
strict_parse_with_error_context(markup)
|
||||||
|
rescue SyntaxError => e
|
||||||
|
case parse_context.error_mode
|
||||||
|
when :strict
|
||||||
|
raise
|
||||||
|
when :warn
|
||||||
|
parse_context.warnings << e
|
||||||
|
end
|
||||||
|
lax_parse(markup)
|
||||||
|
end
|
||||||
|
|
||||||
def parse_with_selected_parser(markup)
|
def parse_with_selected_parser(markup)
|
||||||
case parse_context.error_mode
|
case parse_context.error_mode
|
||||||
when :strict then strict_parse_with_error_context(markup)
|
when :strict then strict_parse_with_error_context(markup)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ module Liquid
|
|||||||
@parse_context = parse_context
|
@parse_context = parse_context
|
||||||
@line_number = parse_context.line_number
|
@line_number = parse_context.line_number
|
||||||
|
|
||||||
parse_with_selected_parser(markup)
|
strict_parse_with_error_mode_fallback(markup)
|
||||||
end
|
end
|
||||||
|
|
||||||
def raw
|
def raw
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ class AssignTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_expression_with_whitespace_in_square_brackets
|
||||||
|
source = "{% assign r = a[ 'b' ] %}{{ r }}"
|
||||||
|
assert_template_result('result', source, 'a' => { 'b' => 'result' })
|
||||||
|
end
|
||||||
|
|
||||||
def test_assign_score_exceeding_resource_limit
|
def test_assign_score_exceeding_resource_limit
|
||||||
t = Template.parse("{% assign foo = 42 %}{% assign bar = 23 %}")
|
t = Template.parse("{% assign foo = 42 %}{% assign bar = 23 %}")
|
||||||
t.resource_limits.assign_score_limit = 1
|
t.resource_limits.assign_score_limit = 1
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ class VariableTest < Minitest::Test
|
|||||||
assert_equal(' worked wonderfully ', template.render!('test' => 'worked wonderfully'))
|
assert_equal(' worked wonderfully ', template.render!('test' => 'worked wonderfully'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_expression_with_whitespace_in_square_brackets
|
||||||
|
assert_template_result('result', "{{ a[ 'b' ] }}", 'a' => { 'b' => 'result' })
|
||||||
|
assert_template_result('result', "{{ a[ [ 'b' ] ] }}", 'b' => 'c', 'a' => { 'c' => 'result' })
|
||||||
|
end
|
||||||
|
|
||||||
def test_ignore_unknown
|
def test_ignore_unknown
|
||||||
template = Template.parse(%({{ test }}))
|
template = Template.parse(%({{ test }}))
|
||||||
assert_equal('', template.render!)
|
assert_equal('', template.render!)
|
||||||
|
|||||||
Reference in New Issue
Block a user