Skip to content

Commit

Permalink
Call String#dup on RUBY_VERSION to avoid crashing on older ruby versions
Browse files Browse the repository at this point in the history
On older versions of rubygems, `Gem::Version.new(...)` calls
`String#strip!` on the argument in the constructor. This causes a
problem on Ruby 1.9.3 where the RUBY_VERSION constant is a frozen
string.

The workaround is to make a copy of this string that is unfrozen, and
`String#dup` seems to work :)
  • Loading branch information
jordansissel committed Nov 3, 2022
1 parent 0a07c00 commit afc7c6f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/fpm/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,11 @@ def erbnew(template_code)
# to invoke ERB.new correctly and without printed warnings.
# References: https://github.com/jordansissel/fpm/issues/1894
# Honestly, I'm not sure if Gem::Version is correct to use in this situation, but it works.
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.1.0")

# on older versions of Ruby, RUBY_VERSION is a frozen string, and
# Gem::Version.new calls String#strip! which throws an exception.
# so we have to call String#dup to get an unfrozen copy.
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new("3.1.0")
# Ruby 3.0.x and older
return ERB.new(template_code, nil, "-")
else
Expand Down

0 comments on commit afc7c6f

Please sign in to comment.