Rename rigid to strict2 mode

This commit is contained in:
Guilherme Carreiro
2025-11-19 13:24:55 +01:00
parent e4276bdf6b
commit a336a2fffd
25 changed files with 140 additions and 132 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ module Liquid
# @param file_system The default file system that is used
# to load templates from.
# @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
# render exceptions.
# @yieldparam environment [Environment] The environment instance that is being built.
+4 -4
View File
@@ -55,15 +55,15 @@ module Liquid
end
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
# 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.
#
# 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
# 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
Expression.parse(markup, @string_scanner, @expression_cache)
+18 -10
View File
@@ -7,16 +7,19 @@ module Liquid
# It's basically doing the same thing the {#parse_with_selected_parser},
# 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,
# 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.
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)
rescue SyntaxError => e
case parse_context.error_mode
when :rigid
rigid_warn
raise
when :strict2
raise
when :strict
raise
@@ -28,12 +31,13 @@ module Liquid
def parse_with_selected_parser(markup)
case parse_context.error_mode
when :rigid then rigid_parse_with_error_context(markup)
when :strict then strict_parse_with_error_context(markup)
when :lax then lax_parse(markup)
when :rigid then rigid_warn && strict2_parse_with_error_context(markup)
when :strict2 then strict2_parse_with_error_context(markup)
when :strict then strict_parse_with_error_context(markup)
when :lax then lax_parse(markup)
when :warn
begin
rigid_parse_with_error_context(markup)
strict2_parse_with_error_context(markup)
rescue SyntaxError => e
parse_context.warnings << e
lax_parse(markup)
@@ -41,14 +45,18 @@ module Liquid
end
end
def rigid_mode?
parse_context.error_mode == :rigid
def strict2_mode?
parse_context.error_mode == :strict2 || parse_context.error_mode == :rigid
end
private
def rigid_parse_with_error_context(markup)
rigid_parse(markup)
def rigid_warn
Deprecations.warn(':rigid', ':strict2')
end
def strict2_parse_with_error_context(markup)
strict2_parse(markup)
rescue SyntaxError => e
e.line_number = line_number
e.markup_context = markup_context(markup)
+4 -4
View File
@@ -86,7 +86,7 @@ module Liquid
private
def rigid_parse(markup)
def strict2_parse(markup)
parser = @parse_context.new_parser(markup)
@left = safe_parse_expression(parser)
parser.consume(:end_of_string)
@@ -107,14 +107,14 @@ module Liquid
def record_when_condition(markup)
body = new_body
if rigid_mode?
parse_rigid_when(markup, body)
if strict2_mode?
parse_strict2_when(markup, body)
else
parse_lax_when(markup, body)
end
end
def parse_rigid_when(markup, body)
def parse_strict2_when(markup, body)
parser = @parse_context.new_parser(markup)
loop do
+1 -1
View File
@@ -56,7 +56,7 @@ module Liquid
private
# cycle [name:] expression(, expression)*
def rigid_parse(markup)
def strict2_parse(markup)
p = @parse_context.new_parser(markup)
@variables = []
+1 -1
View File
@@ -111,7 +111,7 @@ module Liquid
private
def rigid_parse(markup)
def strict2_parse(markup)
strict_parse(markup)
end
+1 -1
View File
@@ -66,7 +66,7 @@ module Liquid
private
def rigid_parse(markup)
def strict2_parse(markup)
strict_parse(markup)
end
+1 -1
View File
@@ -84,7 +84,7 @@ module Liquid
alias_method :parse_context, :options
private :parse_context
def rigid_parse(markup)
def strict2_parse(markup)
p = @parse_context.new_parser(markup)
@template_name_expr = safe_parse_expression(p)
+3 -3
View File
@@ -85,10 +85,10 @@ module Liquid
end
# render (string) (with|for expression)? (as id)? (key: value)*
def rigid_parse(markup)
def strict2_parse(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")
@variable_name_expr = safe_parse_expression(p) if with_or_for
@alias_name = p.consume(:id) if p.id?("as")
@@ -107,7 +107,7 @@ module Liquid
p.consume(:end_of_string)
end
def rigid_template_name(p)
def strict2_template_name(p)
p.consume(:string)
end
+1 -1
View File
@@ -34,7 +34,7 @@ module Liquid
parse_with_selected_parser(markup)
end
def rigid_parse(markup)
def strict2_parse(markup)
p = @parse_context.new_parser(markup)
@variable_name = p.consume(:id)
+1 -1
View File
@@ -25,7 +25,7 @@ module Liquid
# :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.
# :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)
Deprecations.warn("Template.error_mode=", "Environment#error_mode=")
Environment.default.error_mode = mode
+3 -3
View File
@@ -74,14 +74,14 @@ module Liquid
p.consume(:end_of_string)
end
def rigid_parse(markup)
def strict2_parse(markup)
@filters = []
p = @parse_context.new_parser(markup)
return if p.look(:end_of_string)
@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)
end
@@ -156,7 +156,7 @@ module Liquid
# argument = (positional_argument | keyword_argument)
# positional_argument = expression
# keyword_argument = id ":" expression
def rigid_parse_filter_expressions(p)
def strict2_parse_filter_expressions(p)
filtername = p.consume(:id)
filter_args = []
keyword_args = {}