diff --git a/lib/fpm/util.rb b/lib/fpm/util.rb index ed2602de05..46977f7453 100644 --- a/lib/fpm/util.rb +++ b/lib/fpm/util.rb @@ -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