mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Rename rigid to strict2 mode
This commit is contained in:
@@ -103,10 +103,10 @@ Liquid also comes with different parsers that can be used when editing templates
|
|||||||
when templates are invalid. You can enable this new parser like this:
|
when templates are invalid. You can enable this new parser like this:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
Liquid::Environment.default.error_mode = :rigid # Raises a SyntaxError when invalid syntax is used in all tags
|
Liquid::Environment.default.error_mode = :strict2 # Raises a SyntaxError when invalid syntax is used in all tags
|
||||||
Liquid::Environment.default.error_mode = :strict # Raises a SyntaxError when invalid syntax is used in some tags
|
Liquid::Environment.default.error_mode = :strict # Raises a SyntaxError when invalid syntax is used in some tags
|
||||||
Liquid::Environment.default.error_mode = :warn # Adds strict errors to template.errors but continues as normal
|
Liquid::Environment.default.error_mode = :warn # Adds strict errors to template.errors but continues as normal
|
||||||
Liquid::Environment.default.error_mode = :lax # The default mode, accepts almost anything.
|
Liquid::Environment.default.error_mode = :lax # The default mode, accepts almost anything.
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to set the error mode only on specific templates you can pass `:error_mode` as an option to `parse`:
|
If you want to set the error mode only on specific templates you can pass `:error_mode` as an option to `parse`:
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ task :rubocop do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc('runs test suite with lax, strict, and rigid parsers')
|
desc('runs test suite with lax, strict, and strict2 parsers')
|
||||||
task :test do
|
task :test do
|
||||||
ENV['LIQUID_PARSER_MODE'] = 'lax'
|
ENV['LIQUID_PARSER_MODE'] = 'lax'
|
||||||
Rake::Task['base_test'].invoke
|
Rake::Task['base_test'].invoke
|
||||||
@@ -42,7 +42,7 @@ task :test do
|
|||||||
Rake::Task['base_test'].reenable
|
Rake::Task['base_test'].reenable
|
||||||
Rake::Task['base_test'].invoke
|
Rake::Task['base_test'].invoke
|
||||||
|
|
||||||
ENV['LIQUID_PARSER_MODE'] = 'rigid'
|
ENV['LIQUID_PARSER_MODE'] = 'strict2'
|
||||||
Rake::Task['base_test'].reenable
|
Rake::Task['base_test'].reenable
|
||||||
Rake::Task['base_test'].invoke
|
Rake::Task['base_test'].invoke
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ task :test do
|
|||||||
Rake::Task['integration_test'].reenable
|
Rake::Task['integration_test'].reenable
|
||||||
Rake::Task['integration_test'].invoke
|
Rake::Task['integration_test'].invoke
|
||||||
|
|
||||||
ENV['LIQUID_PARSER_MODE'] = 'rigid'
|
ENV['LIQUID_PARSER_MODE'] = 'strict2'
|
||||||
Rake::Task['integration_test'].reenable
|
Rake::Task['integration_test'].reenable
|
||||||
Rake::Task['integration_test'].invoke
|
Rake::Task['integration_test'].invoke
|
||||||
end
|
end
|
||||||
@@ -88,13 +88,13 @@ namespace :benchmark do
|
|||||||
ruby "./performance/benchmark.rb strict"
|
ruby "./performance/benchmark.rb strict"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Run the liquid benchmark with rigid parsing"
|
desc "Run the liquid benchmark with strict2 parsing"
|
||||||
task :rigid do
|
task :strict2 do
|
||||||
ruby "./performance/benchmark.rb rigid"
|
ruby "./performance/benchmark.rb strict2"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Run the liquid benchmark with lax, strict, and rigid parsing"
|
desc "Run the liquid benchmark with lax, strict, and strict2 parsing"
|
||||||
task run: [:lax, :strict, :rigid]
|
task run: [:lax, :strict, :strict2]
|
||||||
|
|
||||||
desc "Run unit benchmarks"
|
desc "Run unit benchmarks"
|
||||||
namespace :unit do
|
namespace :unit do
|
||||||
|
|||||||
+1
-1
@@ -41,6 +41,6 @@ def assigns
|
|||||||
end
|
end
|
||||||
|
|
||||||
puts Liquid::Template
|
puts Liquid::Template
|
||||||
.parse(source, error_mode: :rigid)
|
.parse(source, error_mode: :strict2)
|
||||||
.tap { |t| t.registers[:file_system] = VirtualFileSystem.new }
|
.tap { |t| t.registers[:file_system] = VirtualFileSystem.new }
|
||||||
.render(assigns)
|
.render(assigns)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ module Liquid
|
|||||||
# @param file_system The default file system that is used
|
# @param file_system The default file system that is used
|
||||||
# to load templates from.
|
# to load templates from.
|
||||||
# @param error_mode [Symbol] The default error mode for all templates
|
# @param error_mode [Symbol] The default error mode for all templates
|
||||||
# (either :rigid, :strict, :warn, or :lax).
|
# (either :strict2, :strict, :warn, or :lax).
|
||||||
# @param exception_renderer [Proc] The exception renderer that is used to
|
# @param exception_renderer [Proc] The exception renderer that is used to
|
||||||
# render exceptions.
|
# render exceptions.
|
||||||
# @yieldparam environment [Environment] The environment instance that is being built.
|
# @yieldparam environment [Environment] The environment instance that is being built.
|
||||||
|
|||||||
@@ -55,15 +55,15 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def parse_expression(markup, safe: false)
|
def parse_expression(markup, safe: false)
|
||||||
if !safe && @error_mode == :rigid
|
if !safe && @error_mode == :strict2
|
||||||
# parse_expression is a widely used API. To maintain backward
|
# parse_expression is a widely used API. To maintain backward
|
||||||
# compatibility while raising awareness about rigid parser standards,
|
# compatibility while raising awareness about strict2 parser standards,
|
||||||
# the safe flag supports API users make a deliberate decision.
|
# the safe flag supports API users make a deliberate decision.
|
||||||
#
|
#
|
||||||
# In rigid mode, markup MUST come from a string returned by the parser
|
# In strict2 mode, markup MUST come from a string returned by the parser
|
||||||
# (e.g., parser.expression). We're not calling the parser here to
|
# (e.g., parser.expression). We're not calling the parser here to
|
||||||
# prevent redundant parser overhead.
|
# prevent redundant parser overhead.
|
||||||
raise Liquid::InternalError, "unsafe parse_expression cannot be used in rigid mode"
|
raise Liquid::InternalError, "unsafe parse_expression cannot be used in strict2 mode"
|
||||||
end
|
end
|
||||||
|
|
||||||
Expression.parse(markup, @string_scanner, @expression_cache)
|
Expression.parse(markup, @string_scanner, @expression_cache)
|
||||||
|
|||||||
@@ -7,16 +7,19 @@ module Liquid
|
|||||||
# It's basically doing the same thing the {#parse_with_selected_parser},
|
# It's basically doing the same thing the {#parse_with_selected_parser},
|
||||||
# except this will try the strict parser regardless of the error mode,
|
# except this will try the strict parser regardless of the error mode,
|
||||||
# and fall back to the lax parser if the error mode is lax or warn,
|
# and fall back to the lax parser if the error mode is lax or warn,
|
||||||
# except when in rigid mode where it uses the rigid parser.
|
# except when in strict2 mode where it uses the strict2 parser.
|
||||||
#
|
#
|
||||||
# @deprecated Use {#parse_with_selected_parser} instead.
|
# @deprecated Use {#parse_with_selected_parser} instead.
|
||||||
def strict_parse_with_error_mode_fallback(markup)
|
def strict_parse_with_error_mode_fallback(markup)
|
||||||
return rigid_parse_with_error_context(markup) if rigid_mode?
|
return strict2_parse_with_error_context(markup) if strict2_mode?
|
||||||
|
|
||||||
strict_parse_with_error_context(markup)
|
strict_parse_with_error_context(markup)
|
||||||
rescue SyntaxError => e
|
rescue SyntaxError => e
|
||||||
case parse_context.error_mode
|
case parse_context.error_mode
|
||||||
when :rigid
|
when :rigid
|
||||||
|
rigid_warn
|
||||||
|
raise
|
||||||
|
when :strict2
|
||||||
raise
|
raise
|
||||||
when :strict
|
when :strict
|
||||||
raise
|
raise
|
||||||
@@ -28,12 +31,13 @@ module Liquid
|
|||||||
|
|
||||||
def parse_with_selected_parser(markup)
|
def parse_with_selected_parser(markup)
|
||||||
case parse_context.error_mode
|
case parse_context.error_mode
|
||||||
when :rigid then rigid_parse_with_error_context(markup)
|
when :rigid then rigid_warn && strict2_parse_with_error_context(markup)
|
||||||
when :strict then strict_parse_with_error_context(markup)
|
when :strict2 then strict2_parse_with_error_context(markup)
|
||||||
when :lax then lax_parse(markup)
|
when :strict then strict_parse_with_error_context(markup)
|
||||||
|
when :lax then lax_parse(markup)
|
||||||
when :warn
|
when :warn
|
||||||
begin
|
begin
|
||||||
rigid_parse_with_error_context(markup)
|
strict2_parse_with_error_context(markup)
|
||||||
rescue SyntaxError => e
|
rescue SyntaxError => e
|
||||||
parse_context.warnings << e
|
parse_context.warnings << e
|
||||||
lax_parse(markup)
|
lax_parse(markup)
|
||||||
@@ -41,14 +45,18 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def rigid_mode?
|
def strict2_mode?
|
||||||
parse_context.error_mode == :rigid
|
parse_context.error_mode == :strict2 || parse_context.error_mode == :rigid
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def rigid_parse_with_error_context(markup)
|
def rigid_warn
|
||||||
rigid_parse(markup)
|
Deprecations.warn(':rigid', ':strict2')
|
||||||
|
end
|
||||||
|
|
||||||
|
def strict2_parse_with_error_context(markup)
|
||||||
|
strict2_parse(markup)
|
||||||
rescue SyntaxError => e
|
rescue SyntaxError => e
|
||||||
e.line_number = line_number
|
e.line_number = line_number
|
||||||
e.markup_context = markup_context(markup)
|
e.markup_context = markup_context(markup)
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ module Liquid
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def rigid_parse(markup)
|
def strict2_parse(markup)
|
||||||
parser = @parse_context.new_parser(markup)
|
parser = @parse_context.new_parser(markup)
|
||||||
@left = safe_parse_expression(parser)
|
@left = safe_parse_expression(parser)
|
||||||
parser.consume(:end_of_string)
|
parser.consume(:end_of_string)
|
||||||
@@ -107,14 +107,14 @@ module Liquid
|
|||||||
def record_when_condition(markup)
|
def record_when_condition(markup)
|
||||||
body = new_body
|
body = new_body
|
||||||
|
|
||||||
if rigid_mode?
|
if strict2_mode?
|
||||||
parse_rigid_when(markup, body)
|
parse_strict2_when(markup, body)
|
||||||
else
|
else
|
||||||
parse_lax_when(markup, body)
|
parse_lax_when(markup, body)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_rigid_when(markup, body)
|
def parse_strict2_when(markup, body)
|
||||||
parser = @parse_context.new_parser(markup)
|
parser = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ module Liquid
|
|||||||
private
|
private
|
||||||
|
|
||||||
# cycle [name:] expression(, expression)*
|
# cycle [name:] expression(, expression)*
|
||||||
def rigid_parse(markup)
|
def strict2_parse(markup)
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
@variables = []
|
@variables = []
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ module Liquid
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def rigid_parse(markup)
|
def strict2_parse(markup)
|
||||||
strict_parse(markup)
|
strict_parse(markup)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ module Liquid
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def rigid_parse(markup)
|
def strict2_parse(markup)
|
||||||
strict_parse(markup)
|
strict_parse(markup)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ module Liquid
|
|||||||
alias_method :parse_context, :options
|
alias_method :parse_context, :options
|
||||||
private :parse_context
|
private :parse_context
|
||||||
|
|
||||||
def rigid_parse(markup)
|
def strict2_parse(markup)
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
@template_name_expr = safe_parse_expression(p)
|
@template_name_expr = safe_parse_expression(p)
|
||||||
|
|||||||
@@ -85,10 +85,10 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
# render (string) (with|for expression)? (as id)? (key: value)*
|
# render (string) (with|for expression)? (as id)? (key: value)*
|
||||||
def rigid_parse(markup)
|
def strict2_parse(markup)
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
@template_name_expr = parse_expression(rigid_template_name(p), safe: true)
|
@template_name_expr = parse_expression(strict2_template_name(p), safe: true)
|
||||||
with_or_for = p.id?("for") || p.id?("with")
|
with_or_for = p.id?("for") || p.id?("with")
|
||||||
@variable_name_expr = safe_parse_expression(p) if with_or_for
|
@variable_name_expr = safe_parse_expression(p) if with_or_for
|
||||||
@alias_name = p.consume(:id) if p.id?("as")
|
@alias_name = p.consume(:id) if p.id?("as")
|
||||||
@@ -107,7 +107,7 @@ module Liquid
|
|||||||
p.consume(:end_of_string)
|
p.consume(:end_of_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rigid_template_name(p)
|
def strict2_template_name(p)
|
||||||
p.consume(:string)
|
p.consume(:string)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ module Liquid
|
|||||||
parse_with_selected_parser(markup)
|
parse_with_selected_parser(markup)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rigid_parse(markup)
|
def strict2_parse(markup)
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
@variable_name = p.consume(:id)
|
@variable_name = p.consume(:id)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ module Liquid
|
|||||||
# :lax acts like liquid 2.5 and silently ignores malformed tags in most cases.
|
# :lax acts like liquid 2.5 and silently ignores malformed tags in most cases.
|
||||||
# :warn is the default and will give deprecation warnings when invalid syntax is used.
|
# :warn is the default and will give deprecation warnings when invalid syntax is used.
|
||||||
# :strict enforces correct syntax for most tags
|
# :strict enforces correct syntax for most tags
|
||||||
# :rigid enforces correct syntax for all tags
|
# :strict2 enforces correct syntax for all tags
|
||||||
def error_mode=(mode)
|
def error_mode=(mode)
|
||||||
Deprecations.warn("Template.error_mode=", "Environment#error_mode=")
|
Deprecations.warn("Template.error_mode=", "Environment#error_mode=")
|
||||||
Environment.default.error_mode = mode
|
Environment.default.error_mode = mode
|
||||||
|
|||||||
@@ -74,14 +74,14 @@ module Liquid
|
|||||||
p.consume(:end_of_string)
|
p.consume(:end_of_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rigid_parse(markup)
|
def strict2_parse(markup)
|
||||||
@filters = []
|
@filters = []
|
||||||
p = @parse_context.new_parser(markup)
|
p = @parse_context.new_parser(markup)
|
||||||
|
|
||||||
return if p.look(:end_of_string)
|
return if p.look(:end_of_string)
|
||||||
|
|
||||||
@name = parse_context.safe_parse_expression(p)
|
@name = parse_context.safe_parse_expression(p)
|
||||||
@filters << rigid_parse_filter_expressions(p) while p.consume?(:pipe)
|
@filters << strict2_parse_filter_expressions(p) while p.consume?(:pipe)
|
||||||
p.consume(:end_of_string)
|
p.consume(:end_of_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ module Liquid
|
|||||||
# argument = (positional_argument | keyword_argument)
|
# argument = (positional_argument | keyword_argument)
|
||||||
# positional_argument = expression
|
# positional_argument = expression
|
||||||
# keyword_argument = id ":" expression
|
# keyword_argument = id ":" expression
|
||||||
def rigid_parse_filter_expressions(p)
|
def strict2_parse_filter_expressions(p)
|
||||||
filtername = p.consume(:id)
|
filtername = p.consume(:id)
|
||||||
filter_args = []
|
filter_args = []
|
||||||
keyword_args = {}
|
keyword_args = {}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class CycleTagTest < Minitest::Test
|
|||||||
assert_template_result("a", template2)
|
assert_template_result("a", template2)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error1 = assert_raises(Liquid::SyntaxError) { Template.parse(template1) }
|
error1 = assert_raises(Liquid::SyntaxError) { Template.parse(template1) }
|
||||||
error2 = assert_raises(Liquid::SyntaxError) { Template.parse(template2) }
|
error2 = assert_raises(Liquid::SyntaxError) { Template.parse(template2) }
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ class CycleTagTest < Minitest::Test
|
|||||||
assert_template_result("N", template5)
|
assert_template_result("N", template5)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error1 = assert_raises(Liquid::SyntaxError) { Template.parse(template1) }
|
error1 = assert_raises(Liquid::SyntaxError) { Template.parse(template1) }
|
||||||
error2 = assert_raises(Liquid::SyntaxError) { Template.parse(template2) }
|
error2 = assert_raises(Liquid::SyntaxError) { Template.parse(template2) }
|
||||||
error3 = assert_raises(Liquid::SyntaxError) { Template.parse(template3) }
|
error3 = assert_raises(Liquid::SyntaxError) { Template.parse(template3) }
|
||||||
@@ -157,7 +157,7 @@ class CycleTagTest < Minitest::Test
|
|||||||
refute_nil(Template.parse(template))
|
refute_nil(Template.parse(template))
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
||||||
assert_match(/Unexpected character =/, error.message)
|
assert_match(/Unexpected character =/, error.message)
|
||||||
end
|
end
|
||||||
@@ -174,7 +174,7 @@ class CycleTagTest < Minitest::Test
|
|||||||
refute_nil(Template.parse(template))
|
refute_nil(Template.parse(template))
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
||||||
assert_match(/Unexpected character =/, error.message)
|
assert_match(/Unexpected character =/, error.message)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ class IncludeTagTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rigid_parsing_errors
|
def test_strict2_parsing_errors
|
||||||
with_error_modes(:lax, :strict) do
|
with_error_modes(:lax, :strict) do
|
||||||
assert_template_result(
|
assert_template_result(
|
||||||
'hello value1 value2',
|
'hello value1 value2',
|
||||||
@@ -213,7 +213,7 @@ class IncludeTagTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_syntax_error(
|
assert_syntax_error(
|
||||||
'{% include "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}',
|
'{% include "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}',
|
||||||
)
|
)
|
||||||
@@ -408,7 +408,7 @@ class IncludeTagTest < Minitest::Test
|
|||||||
refute_nil(Template.parse(template))
|
refute_nil(Template.parse(template))
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
||||||
assert_match(/Unexpected character =/, error.message)
|
assert_match(/Unexpected character =/, error.message)
|
||||||
end
|
end
|
||||||
@@ -421,7 +421,7 @@ class IncludeTagTest < Minitest::Test
|
|||||||
refute_nil(Template.parse(template))
|
refute_nil(Template.parse(template))
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
||||||
assert_match(/Unexpected character =/, error.message)
|
assert_match(/Unexpected character =/, error.message)
|
||||||
end
|
end
|
||||||
@@ -434,7 +434,7 @@ class IncludeTagTest < Minitest::Test
|
|||||||
refute_nil(Template.parse(template))
|
refute_nil(Template.parse(template))
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
||||||
assert_match(/Unexpected character =/, error.message)
|
assert_match(/Unexpected character =/, error.message)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
assert_syntax_error("{% assign name = 'snippet' %}{% render name %}")
|
assert_syntax_error("{% assign name = 'snippet' %}{% render name %}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rigid_parsing_errors
|
def test_strict2_parsing_errors
|
||||||
with_error_modes(:lax, :strict) do
|
with_error_modes(:lax, :strict) do
|
||||||
assert_template_result(
|
assert_template_result(
|
||||||
'hello value1 value2',
|
'hello value1 value2',
|
||||||
@@ -114,7 +114,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_syntax_error(
|
assert_syntax_error(
|
||||||
'{% render "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}',
|
'{% render "snippet" !!! arg1: "value1" ~~~ arg2: "value2" %}',
|
||||||
)
|
)
|
||||||
@@ -322,7 +322,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
refute_nil(Template.parse(template))
|
refute_nil(Template.parse(template))
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
||||||
assert_match(/Unexpected character =/, error.message)
|
assert_match(/Unexpected character =/, error.message)
|
||||||
end
|
end
|
||||||
@@ -335,7 +335,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
refute_nil(Template.parse(template))
|
refute_nil(Template.parse(template))
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
||||||
assert_match(/Unexpected character =/, error.message)
|
assert_match(/Unexpected character =/, error.message)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ class TableRowTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_cols_attribute_in_rigid_mode
|
def test_tablerow_with_cols_attribute_in_strict2_mode
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
{% tablerow i in (1..6) cols: 3 %}{{ i }}{% endtablerow %}
|
{% tablerow i in (1..6) cols: 3 %}{{ i }}{% endtablerow %}
|
||||||
LIQUID
|
LIQUID
|
||||||
@@ -270,12 +270,12 @@ class TableRowTest < Minitest::Test
|
|||||||
<tr class="row2"><td class="col1">4</td><td class="col2">5</td><td class="col3">6</td></tr>
|
<tr class="row2"><td class="col1">4</td><td class="col2">5</td><td class="col3">6</td></tr>
|
||||||
OUTPUT
|
OUTPUT
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result(expected, template)
|
assert_template_result(expected, template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_limit_attribute_in_rigid_mode
|
def test_tablerow_with_limit_attribute_in_strict2_mode
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
{% tablerow i in (1..10) limit: 3 %}{{ i }}{% endtablerow %}
|
{% tablerow i in (1..10) limit: 3 %}{{ i }}{% endtablerow %}
|
||||||
LIQUID
|
LIQUID
|
||||||
@@ -285,12 +285,12 @@ class TableRowTest < Minitest::Test
|
|||||||
<td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>
|
<td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>
|
||||||
OUTPUT
|
OUTPUT
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result(expected, template)
|
assert_template_result(expected, template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_offset_attribute_in_rigid_mode
|
def test_tablerow_with_offset_attribute_in_strict2_mode
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
{% tablerow i in (1..5) offset: 2 %}{{ i }}{% endtablerow %}
|
{% tablerow i in (1..5) offset: 2 %}{{ i }}{% endtablerow %}
|
||||||
LIQUID
|
LIQUID
|
||||||
@@ -300,12 +300,12 @@ class TableRowTest < Minitest::Test
|
|||||||
<td class="col1">3</td><td class="col2">4</td><td class="col3">5</td></tr>
|
<td class="col1">3</td><td class="col2">4</td><td class="col3">5</td></tr>
|
||||||
OUTPUT
|
OUTPUT
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result(expected, template)
|
assert_template_result(expected, template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_range_attribute_in_rigid_mode
|
def test_tablerow_with_range_attribute_in_strict2_mode
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
{% tablerow i in (1..3) range: (1..10) %}{{ i }}{% endtablerow %}
|
{% tablerow i in (1..3) range: (1..10) %}{{ i }}{% endtablerow %}
|
||||||
LIQUID
|
LIQUID
|
||||||
@@ -315,12 +315,12 @@ class TableRowTest < Minitest::Test
|
|||||||
<td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>
|
<td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>
|
||||||
OUTPUT
|
OUTPUT
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result(expected, template)
|
assert_template_result(expected, template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_multiple_attributes_in_rigid_mode
|
def test_tablerow_with_multiple_attributes_in_strict2_mode
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
{% tablerow i in (1..10) cols: 2, limit: 4, offset: 1 %}{{ i }}{% endtablerow %}
|
{% tablerow i in (1..10) cols: 2, limit: 4, offset: 1 %}{{ i }}{% endtablerow %}
|
||||||
LIQUID
|
LIQUID
|
||||||
@@ -331,12 +331,12 @@ class TableRowTest < Minitest::Test
|
|||||||
<tr class="row2"><td class="col1">4</td><td class="col2">5</td></tr>
|
<tr class="row2"><td class="col1">4</td><td class="col2">5</td></tr>
|
||||||
OUTPUT
|
OUTPUT
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result(expected, template)
|
assert_template_result(expected, template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_variable_collection_in_rigid_mode
|
def test_tablerow_with_variable_collection_in_strict2_mode
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
{% tablerow n in numbers cols: 2 %}{{ n }}{% endtablerow %}
|
{% tablerow n in numbers cols: 2 %}{{ n }}{% endtablerow %}
|
||||||
LIQUID
|
LIQUID
|
||||||
@@ -347,12 +347,12 @@ class TableRowTest < Minitest::Test
|
|||||||
<tr class="row2"><td class="col1">3</td><td class="col2">4</td></tr>
|
<tr class="row2"><td class="col1">3</td><td class="col2">4</td></tr>
|
||||||
OUTPUT
|
OUTPUT
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result(expected, template, { 'numbers' => [1, 2, 3, 4] })
|
assert_template_result(expected, template, { 'numbers' => [1, 2, 3, 4] })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_dotted_access_in_rigid_mode
|
def test_tablerow_with_dotted_access_in_strict2_mode
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
{% tablerow n in obj.numbers cols: 2 %}{{ n }}{% endtablerow %}
|
{% tablerow n in obj.numbers cols: 2 %}{{ n }}{% endtablerow %}
|
||||||
LIQUID
|
LIQUID
|
||||||
@@ -363,12 +363,12 @@ class TableRowTest < Minitest::Test
|
|||||||
<tr class="row2"><td class="col1">3</td><td class="col2">4</td></tr>
|
<tr class="row2"><td class="col1">3</td><td class="col2">4</td></tr>
|
||||||
OUTPUT
|
OUTPUT
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result(expected, template, { 'obj' => { 'numbers' => [1, 2, 3, 4] } })
|
assert_template_result(expected, template, { 'obj' => { 'numbers' => [1, 2, 3, 4] } })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_bracketed_access_in_rigid_mode
|
def test_tablerow_with_bracketed_access_in_strict2_mode
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
{% tablerow n in obj["numbers"] cols: 2 %}{{ n }}{% endtablerow %}
|
{% tablerow n in obj["numbers"] cols: 2 %}{{ n }}{% endtablerow %}
|
||||||
LIQUID
|
LIQUID
|
||||||
@@ -378,12 +378,12 @@ class TableRowTest < Minitest::Test
|
|||||||
<td class="col1">10</td><td class="col2">20</td></tr>
|
<td class="col1">10</td><td class="col2">20</td></tr>
|
||||||
OUTPUT
|
OUTPUT
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result(expected, template, { 'obj' => { 'numbers' => [10, 20] } })
|
assert_template_result(expected, template, { 'obj' => { 'numbers' => [10, 20] } })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_without_attributes_in_rigid_mode
|
def test_tablerow_without_attributes_in_strict2_mode
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
{% tablerow i in (1..3) %}{{ i }}{% endtablerow %}
|
{% tablerow i in (1..3) %}{{ i }}{% endtablerow %}
|
||||||
LIQUID
|
LIQUID
|
||||||
@@ -393,30 +393,30 @@ class TableRowTest < Minitest::Test
|
|||||||
<td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>
|
<td class="col1">1</td><td class="col2">2</td><td class="col3">3</td></tr>
|
||||||
OUTPUT
|
OUTPUT
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result(expected, template)
|
assert_template_result(expected, template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_without_in_keyword_in_rigid_mode
|
def test_tablerow_without_in_keyword_in_strict2_mode
|
||||||
template = '{% tablerow i (1..10) %}{{ i }}{% endtablerow %}'
|
template = '{% tablerow i (1..10) %}{{ i }}{% endtablerow %}'
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(SyntaxError) { Template.parse(template) }
|
error = assert_raises(SyntaxError) { Template.parse(template) }
|
||||||
assert_equal("Liquid syntax error: For loops require an 'in' clause in \"i (1..10)\"", error.message)
|
assert_equal("Liquid syntax error: For loops require an 'in' clause in \"i (1..10)\"", error.message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_multiple_invalid_attributes_reports_first_in_rigid_mode
|
def test_tablerow_with_multiple_invalid_attributes_reports_first_in_strict2_mode
|
||||||
template = '{% tablerow i in (1..10) invalid1: 5, invalid2: 10 %}{{ i }}{% endtablerow %}'
|
template = '{% tablerow i in (1..10) invalid1: 5, invalid2: 10 %}{{ i }}{% endtablerow %}'
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(SyntaxError) { Template.parse(template) }
|
error = assert_raises(SyntaxError) { Template.parse(template) }
|
||||||
assert_equal("Liquid syntax error: Invalid attribute 'invalid1' in tablerow loop. Valid attributes are cols, limit, offset, and range in \"i in (1..10) invalid1: 5, invalid2: 10\"", error.message)
|
assert_equal("Liquid syntax error: Invalid attribute 'invalid1' in tablerow loop. Valid attributes are cols, limit, offset, and range in \"i in (1..10) invalid1: 5, invalid2: 10\"", error.message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_empty_collection_in_rigid_mode
|
def test_tablerow_with_empty_collection_in_strict2_mode
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
{% tablerow i in empty_array cols: 2 %}{{ i }}{% endtablerow %}
|
{% tablerow i in empty_array cols: 2 %}{{ i }}{% endtablerow %}
|
||||||
LIQUID
|
LIQUID
|
||||||
@@ -426,12 +426,12 @@ class TableRowTest < Minitest::Test
|
|||||||
</tr>
|
</tr>
|
||||||
OUTPUT
|
OUTPUT
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result(expected, template, { 'empty_array' => [] })
|
assert_template_result(expected, template, { 'empty_array' => [] })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_invalid_attribute_strict_vs_rigid
|
def test_tablerow_with_invalid_attribute_strict_vs_strict2
|
||||||
template = '{% tablerow i in (1..5) invalid_attr: 10 %}{{ i }}{% endtablerow %}'
|
template = '{% tablerow i in (1..5) invalid_attr: 10 %}{{ i }}{% endtablerow %}'
|
||||||
|
|
||||||
expected = <<~OUTPUT
|
expected = <<~OUTPUT
|
||||||
@@ -443,13 +443,13 @@ class TableRowTest < Minitest::Test
|
|||||||
assert_template_result(expected, template)
|
assert_template_result(expected, template)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(SyntaxError) { Template.parse(template) }
|
error = assert_raises(SyntaxError) { Template.parse(template) }
|
||||||
assert_match(/Invalid attribute 'invalid_attr'/, error.message)
|
assert_match(/Invalid attribute 'invalid_attr'/, error.message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tablerow_with_invalid_expression_strict_vs_rigid
|
def test_tablerow_with_invalid_expression_strict_vs_strict2
|
||||||
template = '{% tablerow i in (1..5) limit: foo=>bar %}{{ i }}{% endtablerow %}'
|
template = '{% tablerow i in (1..5) limit: foo=>bar %}{{ i }}{% endtablerow %}'
|
||||||
|
|
||||||
with_error_modes(:lax, :strict) do
|
with_error_modes(:lax, :strict) do
|
||||||
@@ -460,7 +460,7 @@ class TableRowTest < Minitest::Test
|
|||||||
assert_template_result(expected, template)
|
assert_template_result(expected, template)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(SyntaxError) { Template.parse(template) }
|
error = assert_raises(SyntaxError) { Template.parse(template) }
|
||||||
assert_match(/Unexpected character =/, error.message)
|
assert_match(/Unexpected character =/, error.message)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ class VariableTest < Minitest::Test
|
|||||||
assert_match(/is not a valid expression/, error.message)
|
assert_match(/is not a valid expression/, error.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result('helloworld', template)
|
assert_template_result('helloworld', template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -231,7 +231,7 @@ class VariableTest < Minitest::Test
|
|||||||
assert_match(/is not a valid expression/, error.message)
|
assert_match(/is not a valid expression/, error.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result('hello12', template)
|
assert_template_result('hello12', template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -244,7 +244,7 @@ class VariableTest < Minitest::Test
|
|||||||
assert_match(/is not a valid expression/, error.message)
|
assert_match(/is not a valid expression/, error.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result('TEST', template)
|
assert_template_result('TEST', template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -257,7 +257,7 @@ class VariableTest < Minitest::Test
|
|||||||
assert_match(/is not a valid expression/, error.message)
|
assert_match(/is not a valid expression/, error.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result('TESTX', template)
|
assert_template_result('TESTX', template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -270,7 +270,7 @@ class VariableTest < Minitest::Test
|
|||||||
assert_match(/is not a valid expression/, error.message)
|
assert_match(/is not a valid expression/, error.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
assert_template_result('TESTX', template)
|
assert_template_result('TESTX', template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -176,19 +176,19 @@ class ConditionUnitTest < Minitest::Test
|
|||||||
assert_equal(['title'], result.lookups)
|
assert_equal(['title'], result.lookups)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parse_expression_in_rigid_mode_raises_internal_error
|
def test_parse_expression_in_strict2_mode_raises_internal_error
|
||||||
environment = Environment.build(error_mode: :rigid)
|
environment = Environment.build(error_mode: :strict2)
|
||||||
parse_context = ParseContext.new(environment: environment)
|
parse_context = ParseContext.new(environment: environment)
|
||||||
|
|
||||||
error = assert_raises(Liquid::InternalError) do
|
error = assert_raises(Liquid::InternalError) do
|
||||||
Condition.parse_expression(parse_context, 'product.title')
|
Condition.parse_expression(parse_context, 'product.title')
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_match(/unsafe parse_expression cannot be used in rigid mode/, error.message)
|
assert_match(/unsafe parse_expression cannot be used in strict2 mode/, error.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parse_expression_with_safe_true_in_rigid_mode
|
def test_parse_expression_with_safe_true_in_strict2_mode
|
||||||
environment = Environment.build(error_mode: :rigid)
|
environment = Environment.build(error_mode: :strict2)
|
||||||
parse_context = ParseContext.new(environment: environment)
|
parse_context = ParseContext.new(environment: environment)
|
||||||
result = Condition.parse_expression(parse_context, 'product.title', safe: true)
|
result = Condition.parse_expression(parse_context, 'product.title', safe: true)
|
||||||
|
|
||||||
|
|||||||
@@ -9,32 +9,32 @@ class ParseContextUnitTest < Minitest::Test
|
|||||||
parser_strict = strict_parse_context.new_parser('product.title')
|
parser_strict = strict_parse_context.new_parser('product.title')
|
||||||
result_strict = strict_parse_context.safe_parse_expression(parser_strict)
|
result_strict = strict_parse_context.safe_parse_expression(parser_strict)
|
||||||
|
|
||||||
parser_rigid = rigid_parse_context.new_parser('product.title')
|
parser_strict2 = strict2_parse_context.new_parser('product.title')
|
||||||
result_rigid = rigid_parse_context.safe_parse_expression(parser_rigid)
|
result_strict2 = strict2_parse_context.safe_parse_expression(parser_strict2)
|
||||||
|
|
||||||
assert_instance_of(VariableLookup, result_strict)
|
assert_instance_of(VariableLookup, result_strict)
|
||||||
assert_equal('product', result_strict.name)
|
assert_equal('product', result_strict.name)
|
||||||
assert_equal(['title'], result_strict.lookups)
|
assert_equal(['title'], result_strict.lookups)
|
||||||
|
|
||||||
assert_instance_of(VariableLookup, result_rigid)
|
assert_instance_of(VariableLookup, result_strict2)
|
||||||
assert_equal('product', result_rigid.name)
|
assert_equal('product', result_strict2.name)
|
||||||
assert_equal(['title'], result_rigid.lookups)
|
assert_equal(['title'], result_strict2.lookups)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_safe_parse_expression_raises_syntax_error_for_invalid_expression
|
def test_safe_parse_expression_raises_syntax_error_for_invalid_expression
|
||||||
parser_strict = strict_parse_context.new_parser('')
|
parser_strict = strict_parse_context.new_parser('')
|
||||||
parser_rigid = rigid_parse_context.new_parser('')
|
parser_strict2 = strict2_parse_context.new_parser('')
|
||||||
|
|
||||||
error_strict = assert_raises(Liquid::SyntaxError) do
|
error_strict = assert_raises(Liquid::SyntaxError) do
|
||||||
strict_parse_context.safe_parse_expression(parser_strict)
|
strict_parse_context.safe_parse_expression(parser_strict)
|
||||||
end
|
end
|
||||||
assert_match(/is not a valid expression/, error_strict.message)
|
assert_match(/is not a valid expression/, error_strict.message)
|
||||||
|
|
||||||
error_rigid = assert_raises(Liquid::SyntaxError) do
|
error_strict2 = assert_raises(Liquid::SyntaxError) do
|
||||||
rigid_parse_context.safe_parse_expression(parser_rigid)
|
strict2_parse_context.safe_parse_expression(parser_strict2)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_match(/is not a valid expression/, error_rigid.message)
|
assert_match(/is not a valid expression/, error_strict2.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parse_expression_with_variable_lookup
|
def test_parse_expression_with_variable_lookup
|
||||||
@@ -45,10 +45,10 @@ class ParseContextUnitTest < Minitest::Test
|
|||||||
assert_equal(['title'], result_strict.lookups)
|
assert_equal(['title'], result_strict.lookups)
|
||||||
|
|
||||||
error = assert_raises(Liquid::InternalError) do
|
error = assert_raises(Liquid::InternalError) do
|
||||||
rigid_parse_context.parse_expression('product.title')
|
strict2_parse_context.parse_expression('product.title')
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_match(/unsafe parse_expression cannot be used in rigid mode/, error.message)
|
assert_match(/unsafe parse_expression cannot be used in strict2 mode/, error.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parse_expression_with_safe_true
|
def test_parse_expression_with_safe_true
|
||||||
@@ -58,11 +58,11 @@ class ParseContextUnitTest < Minitest::Test
|
|||||||
assert_equal('product', result_strict.name)
|
assert_equal('product', result_strict.name)
|
||||||
assert_equal(['title'], result_strict.lookups)
|
assert_equal(['title'], result_strict.lookups)
|
||||||
|
|
||||||
result_rigid = rigid_parse_context.parse_expression('product.title', safe: true)
|
result_strict2 = strict2_parse_context.parse_expression('product.title', safe: true)
|
||||||
|
|
||||||
assert_instance_of(VariableLookup, result_rigid)
|
assert_instance_of(VariableLookup, result_strict2)
|
||||||
assert_equal('product', result_rigid.name)
|
assert_equal('product', result_strict2.name)
|
||||||
assert_equal(['title'], result_rigid.lookups)
|
assert_equal(['title'], result_strict2.lookups)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parse_expression_with_empty_string
|
def test_parse_expression_with_empty_string
|
||||||
@@ -70,40 +70,40 @@ class ParseContextUnitTest < Minitest::Test
|
|||||||
assert_nil(result_strict)
|
assert_nil(result_strict)
|
||||||
|
|
||||||
error = assert_raises(Liquid::InternalError) do
|
error = assert_raises(Liquid::InternalError) do
|
||||||
rigid_parse_context.parse_expression('')
|
strict2_parse_context.parse_expression('')
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_match(/unsafe parse_expression cannot be used in rigid mode/, error.message)
|
assert_match(/unsafe parse_expression cannot be used in strict2 mode/, error.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parse_expression_with_empty_string_and_safe_true
|
def test_parse_expression_with_empty_string_and_safe_true
|
||||||
result_strict = strict_parse_context.parse_expression('', safe: true)
|
result_strict = strict_parse_context.parse_expression('', safe: true)
|
||||||
assert_nil(result_strict)
|
assert_nil(result_strict)
|
||||||
|
|
||||||
result_rigid = rigid_parse_context.parse_expression('', safe: true)
|
result_strict2 = strict2_parse_context.parse_expression('', safe: true)
|
||||||
assert_nil(result_rigid)
|
assert_nil(result_strict2)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_safe_parse_expression_advances_parser_pointer
|
def test_safe_parse_expression_advances_parser_pointer
|
||||||
parser = rigid_parse_context.new_parser('foo, bar')
|
parser = strict2_parse_context.new_parser('foo, bar')
|
||||||
|
|
||||||
# safe_parse_expression consumes "foo"
|
# safe_parse_expression consumes "foo"
|
||||||
first_result = rigid_parse_context.safe_parse_expression(parser)
|
first_result = strict2_parse_context.safe_parse_expression(parser)
|
||||||
assert_instance_of(VariableLookup, first_result)
|
assert_instance_of(VariableLookup, first_result)
|
||||||
assert_equal('foo', first_result.name)
|
assert_equal('foo', first_result.name)
|
||||||
|
|
||||||
parser.consume(:comma)
|
parser.consume(:comma)
|
||||||
|
|
||||||
# safe_parse_expression consumes "bar"
|
# safe_parse_expression consumes "bar"
|
||||||
second_result = rigid_parse_context.safe_parse_expression(parser)
|
second_result = strict2_parse_context.safe_parse_expression(parser)
|
||||||
assert_instance_of(VariableLookup, second_result)
|
assert_instance_of(VariableLookup, second_result)
|
||||||
assert_equal('bar', second_result.name)
|
assert_equal('bar', second_result.name)
|
||||||
|
|
||||||
parser.consume(:end_of_string)
|
parser.consume(:end_of_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parse_expression_with_whitespace_in_rigid_mode
|
def test_parse_expression_with_whitespace_in_strict2_mode
|
||||||
result = rigid_parse_context.parse_expression(' ', safe: true)
|
result = strict2_parse_context.parse_expression(' ', safe: true)
|
||||||
assert_nil(result)
|
assert_nil(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -115,9 +115,9 @@ class ParseContextUnitTest < Minitest::Test
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rigid_parse_context
|
def strict2_parse_context
|
||||||
@rigid_parse_context ||= ParseContext.new(
|
@strict2_parse_context ||= ParseContext.new(
|
||||||
environment: Environment.build(error_mode: :rigid),
|
environment: Environment.build(error_mode: :strict2),
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ class PartialCacheUnitTest < Minitest::Test
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
[:lax, :warn, :strict, :rigid].each do |error_mode|
|
[:lax, :warn, :strict, :strict2].each do |error_mode|
|
||||||
Liquid::PartialCache.load(
|
Liquid::PartialCache.load(
|
||||||
'my_partial',
|
'my_partial',
|
||||||
context: context,
|
context: context,
|
||||||
@@ -193,7 +193,7 @@ class PartialCacheUnitTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
assert_equal(
|
assert_equal(
|
||||||
["my_partial:lax", "my_partial:warn", "my_partial:strict", "my_partial:rigid"],
|
["my_partial:lax", "my_partial:warn", "my_partial:strict", "my_partial:strict2"],
|
||||||
context.registers[:cached_partials].keys,
|
context.registers[:cached_partials].keys,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class CaseTagUnitTest < Minitest::Test
|
|||||||
assert_template_result("one", template)
|
assert_template_result("one", template)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
||||||
|
|
||||||
assert_match(/Expected end_of_string but found/, error.message)
|
assert_match(/Expected end_of_string but found/, error.message)
|
||||||
@@ -45,7 +45,7 @@ class CaseTagUnitTest < Minitest::Test
|
|||||||
assert_template_result("one", template)
|
assert_template_result("one", template)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
||||||
|
|
||||||
assert_match(/Expected end_of_string but found/, error.message)
|
assert_match(/Expected end_of_string but found/, error.message)
|
||||||
@@ -62,7 +62,7 @@ class CaseTagUnitTest < Minitest::Test
|
|||||||
{%- endcase -%}
|
{%- endcase -%}
|
||||||
LIQUID
|
LIQUID
|
||||||
|
|
||||||
with_error_modes(:lax, :strict, :rigid) do
|
with_error_modes(:lax, :strict, :strict2) do
|
||||||
assert_template_result("one", template)
|
assert_template_result("one", template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -77,7 +77,7 @@ class CaseTagUnitTest < Minitest::Test
|
|||||||
{%- endcase -%}
|
{%- endcase -%}
|
||||||
LIQUID
|
LIQUID
|
||||||
|
|
||||||
with_error_modes(:lax, :strict, :rigid) do
|
with_error_modes(:lax, :strict, :strict2) do
|
||||||
assert_template_result("one", template)
|
assert_template_result("one", template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -97,7 +97,7 @@ class CaseTagUnitTest < Minitest::Test
|
|||||||
assert_template_result("one", template, assigns)
|
assert_template_result("one", template, assigns)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
||||||
|
|
||||||
assert_match(/Unexpected character =/, error.message)
|
assert_match(/Unexpected character =/, error.message)
|
||||||
@@ -119,7 +119,7 @@ class CaseTagUnitTest < Minitest::Test
|
|||||||
assert_template_result("one", template, assigns)
|
assert_template_result("one", template, assigns)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
error = assert_raises(Liquid::SyntaxError) { Template.parse(template) }
|
||||||
|
|
||||||
assert_match(/Unexpected character =/, error.message)
|
assert_match(/Unexpected character =/, error.message)
|
||||||
|
|||||||
@@ -161,8 +161,8 @@ class VariableUnitTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rigid_filter_argument_parsing
|
def test_strict2_filter_argument_parsing
|
||||||
with_error_modes(:rigid) do
|
with_error_modes(:strict2) do
|
||||||
# optional colon
|
# optional colon
|
||||||
var = create_variable(%(n | f1 | f2:))
|
var = create_variable(%(n | f1 | f2:))
|
||||||
assert_equal([['f1', []], ['f2', []]], var.filters)
|
assert_equal([['f1', []], ['f2', []]], var.filters)
|
||||||
|
|||||||
Reference in New Issue
Block a user