Skip to content

Commit

Permalink
Merge pull request #719 from casperisfine/fix-erb-version-check
Browse files Browse the repository at this point in the history
Better ERB keyword argument check
  • Loading branch information
byroot authored Oct 13, 2021
2 parents e374fd3 + 355b04c commit 019bbae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket

## Master

- Better detect the ERB version to avoid deprecation warnings. [#719](https://github.com/rails/sprockets/pull/719)
- Allow assets already fingerprinted to be served through `Sprockets::Server`
- Do not fingerprint files that already contain a valid digest in their name
- Remove remaining support for Ruby < 2.4.[#672](https://github.com/rails/sprockets/pull/672)
Expand Down
10 changes: 8 additions & 2 deletions lib/sprockets/erb_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def initialize(&block)
end

def call(input)
match = ERB.version.match(/\Aerb\.rb \[(?<version>[^ ]+) /)
if match && match[:version] >= "2.2.0" # Ruby 2.6+
if keyword_constructor? # Ruby 2.6+
engine = ::ERB.new(input[:data], trim_mode: '<>')
else
engine = ::ERB.new(input[:data], nil, '<>')
Expand All @@ -34,4 +33,11 @@ def call(input)
data = engine.result(context.instance_eval('binding'))
context.metadata.merge(data: data)
end

private

def keyword_constructor?
return @keyword_constructor if defined? @keyword_constructor
@keyword_constructor = ::ERB.instance_method(:initialize).parameters.include?([:key, :trim_mode])
end
end

0 comments on commit 019bbae

Please sign in to comment.