From afc7c6f4340d5c267456c4b2ec72fc3b379de265 Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Wed, 2 Nov 2022 16:50:26 -0700 Subject: [PATCH] Call String#dup on RUBY_VERSION to avoid crashing on older ruby versions 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 :) --- lib/fpm/util.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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