Skip to content

Commit 3841aa9

Browse files
committed
Remove :error_mode
1 parent f6fbd6b commit 3841aa9

24 files changed

Lines changed: 202 additions & 386 deletions

Rakefile

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ task :rubocop do
3333
end
3434
end
3535

36-
desc('runs test suite with strict2 parser')
36+
desc('runs test suite')
3737
task :test do
38-
ENV['LIQUID_PARSER_MODE'] = 'strict2'
3938
Rake::Task['base_test'].reenable
4039
Rake::Task['base_test'].invoke
4140

4241
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'truffleruby'
43-
ENV['LIQUID_PARSER_MODE'] = 'strict2'
4442
Rake::Task['integration_test'].reenable
4543
Rake::Task['integration_test'].invoke
4644
end
@@ -63,13 +61,10 @@ task release: :build do
6361
end
6462

6563
namespace :benchmark do
66-
desc "Run the liquid benchmark with strict2 parsing"
67-
task :strict2 do
68-
ruby "./performance/benchmark.rb strict2"
69-
end
70-
7164
desc "Run the liquid benchmark"
72-
task run: [:strict2]
65+
task :run do
66+
ruby "./performance/benchmark.rb"
67+
end
7368

7469
desc "Run unit benchmarks"
7570
namespace :unit do
@@ -101,11 +96,6 @@ namespace :profile do
10196
task :run do
10297
ruby "./performance/profile.rb"
10398
end
104-
105-
desc "Run the liquid profile/performance coverage with strict2 parsing"
106-
task :strict2 do
107-
ruby "./performance/profile.rb strict2"
108-
end
10999
end
110100

111101
namespace :memory_profile do

lib/liquid/environment.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ module Liquid
44
# The Environment is the container for all configuration options of Liquid, such as
55
# the registered tags, filters, and the default error mode.
66
class Environment
7-
# The default error mode for all templates. This can be overridden on a
8-
# per-template basis.
9-
attr_accessor :error_mode
10-
117
# The tags that are available to use in the template.
128
attr_accessor :tags
139

@@ -33,17 +29,14 @@ class << self
3329
# the template.
3430
# @param file_system The default file system that is used
3531
# to load templates from.
36-
# @param error_mode [Symbol] The default error mode for all templates
37-
# (:strict2).
3832
# @param exception_renderer [Proc] The exception renderer that is used to
3933
# render exceptions.
4034
# @yieldparam environment [Environment] The environment instance that is being built.
4135
# @return [Environment] The new environment instance.
42-
def build(tags: nil, file_system: nil, error_mode: nil, exception_renderer: nil)
36+
def build(tags: nil, file_system: nil, exception_renderer: nil)
4337
ret = new
4438
ret.tags = tags if tags
4539
ret.file_system = file_system if file_system
46-
ret.error_mode = error_mode if error_mode
4740
ret.exception_renderer = exception_renderer if exception_renderer
4841
yield ret if block_given?
4942
ret.freeze
@@ -75,7 +68,6 @@ def dangerously_override(environment)
7568
# @api private
7669
def initialize
7770
@tags = Tags::STANDARD_TAGS.dup
78-
@error_mode = :strict2
7971
@strainer_template = Class.new(StrainerTemplate).tap do |klass|
8072
klass.add_filter(StandardFilters)
8173
end

lib/liquid/parse_context.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Liquid
44
class ParseContext
55
attr_accessor :locale, :line_number, :trim_whitespace, :depth
6-
attr_reader :partial, :warnings, :error_mode, :environment
6+
attr_reader :partial, :warnings, :environment
77

88
def initialize(options = Const::EMPTY_HASH)
99
@environment = options.fetch(:environment, Environment.default)
@@ -55,25 +55,19 @@ def safe_parse_expression(parser)
5555
end
5656

5757
def parse_expression(markup, safe: false)
58-
if !safe && @error_mode == :strict2
59-
# parse_expression is a widely used API. To maintain backward
60-
# compatibility while raising awareness about strict2 parser standards,
61-
# the safe flag supports API users make a deliberate decision.
62-
#
63-
# In strict2 mode, markup MUST come from a string returned by the parser
64-
# (e.g., parser.expression). We're not calling the parser here to
65-
# prevent redundant parser overhead.
66-
raise Liquid::InternalError, "unsafe parse_expression cannot be used in strict2 mode"
67-
end
58+
# markup MUST come from a string returned by the parser
59+
# (e.g., parser.expression). We're not calling the parser here to
60+
# prevent redundant parser overhead. The `safe` opt-in
61+
# exists to ensure it is not accidentally still called with
62+
# the result of a regex.
63+
raise Liquid::InternalError, "unsafe parse_expression cannot be used" unless safe
6864

6965
Expression.parse(markup, @string_scanner, @expression_cache)
7066
end
7167

7268
def partial=(value)
7369
@partial = value
7470
@options = value ? partial_options : @template_options
75-
76-
@error_mode = @options[:error_mode] || @environment.error_mode
7771
end
7872

7973
def partial_options

lib/liquid/partial_cache.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Liquid
44
class PartialCache
55
def self.load(template_name, context:, parse_context:)
66
cached_partials = context.registers[:cached_partials]
7-
cache_key = "#{template_name}:#{parse_context.error_mode}"
7+
cache_key = template_name.to_s
88
cached = cached_partials[cache_key]
99
return cached if cached
1010

lib/liquid/template.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,6 @@ class Template
2121
attr_reader :profiler
2222

2323
class << self
24-
# Sets how strict the parser should be.
25-
# :strict2 enforces correct syntax for all tags
26-
def error_mode=(mode)
27-
Deprecations.warn("Template.error_mode=", "Environment#error_mode=")
28-
Environment.default.error_mode = mode
29-
end
30-
31-
def error_mode
32-
Environment.default.error_mode
33-
end
34-
3524
def default_exception_renderer=(renderer)
3625
Deprecations.warn("Template.default_exception_renderer=", "Environment#exception_renderer=")
3726
Environment.default.exception_renderer = renderer

performance/benchmark.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require_relative 'theme_runner'
55

66
RubyVM::YJIT.enable if defined?(RubyVM::YJIT)
7-
Liquid::Environment.default.error_mode = ARGV.first.to_sym if ARGV.first
87

98
profiler = ThemeRunner.new
109

performance/memory_profile.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ def sanitize(string)
5353
end
5454
end
5555

56-
Liquid::Template.error_mode = ARGV.first.to_sym if ARGV.first
57-
5856
runner = ThemeRunner.new
5957
Profiler.run do |x|
6058
x.profile('parse') { runner.compile }

performance/profile.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'stackprof'
44
require_relative 'theme_runner'
55

6-
Liquid::Template.error_mode = ARGV.first.to_sym if ARGV.first
76
profiler = ThemeRunner.new
87
profiler.run
98

test/integration/assign_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ def test_assign_syntax_error
3939
assert_match_syntax_error(/assign/, '{% assign foo not values %}.')
4040
end
4141

42-
def test_assign_uses_error_mode
42+
def test_assign_throws_on_unsupported_syntax
4343
assert_match_syntax_error(
4444
"Expected dotdot but found pipe",
4545
"{% assign foo = ('X' | downcase) %}",
46-
error_mode: :rigid,
4746
)
4847
end
4948

test/integration/context_test.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,9 @@ def notice(output)
632632
end
633633

634634
def test_has_key_will_not_add_an_error_for_missing_keys
635-
with_error_modes(:rigid) do
636-
context = Context.new
637-
context.key?('unknown')
638-
assert_empty(context.errors)
639-
end
635+
context = Context.new
636+
context.key?('unknown')
637+
assert_empty(context.errors)
640638
end
641639

642640
def test_key_lookup_will_raise_for_missing_keys_when_strict_variables_is_enabled

0 commit comments

Comments
 (0)