diff --git a/lib/liquid/parser_switching.rb b/lib/liquid/parser_switching.rb index e1047632..a978dc43 100644 --- a/lib/liquid/parser_switching.rb +++ b/lib/liquid/parser_switching.rb @@ -2,14 +2,17 @@ module Liquid module ParserSwitching + # Do not use this. Use parse_with_selected_parser instead. + # It's basically doing the same thing, except this will use strict_parse regardless + # of the error mode and fallback only if strict throws. 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 :rigid raise + when :strict + raise when :warn parse_context.warnings << e end @@ -18,8 +21,8 @@ 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 :rigid then strict_parse_with_error_context(markup) when :lax then lax_parse(markup) when :warn begin @@ -33,6 +36,14 @@ module Liquid private + def rigid_parse_with_error_context(markup) + respond_to?(:rigid_parse) ? rigid_parse(markup) : strict_parse(markup) + rescue SyntaxError => e + e.line_number = line_number + e.markup_context = markup_context(markup) + raise e + end + def strict_parse_with_error_context(markup) strict_parse(markup) rescue SyntaxError => e diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index a6d80e0a..acda1e4d 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -25,6 +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 will enforce correct syntax. + # :rigid is stricter even. def error_mode=(mode) Deprecations.warn("Template.error_mode=", "Environment#error_mode=") Environment.default.error_mode = mode