Skip to content

Commit

Permalink
(PUP-7523) Dup RUBY_VERSION in Gem::Version
Browse files Browse the repository at this point in the history
The following fails on some buggy versions of rubygems in ruby 1.9.3[1]:

    irb(main):001:0> Gem::Version.new(RUBY_VERSION)
    RuntimeError: can't modify frozen String

As a result, puppet will not run when installed as a gem, until rubygems
is updated.

This commits `dup`s the version string as is done elsewhere[2].

[1] rubygems/bundler#3187
[2]
puppetlabs/modulesync_configs@be386b4
  • Loading branch information
joshcooper committed May 11, 2017
1 parent 8d9e0f4 commit fb9995d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Gem::Specification.new do |s|
# Beaker 3.0.0 to 3.10.0 depends on net-ssh 3.3.0beta1
# Beaker 3.11.0+ depends on net-ssh 4.0+
# be lenient to allow module testing where Beaker and Puppet are in same Gemfile
s.add_runtime_dependency(%q<net-ssh>, [">= 3.0", "< 5"]) if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0.0')
s.add_runtime_dependency(%q<net-ssh>, [">= 3.0", "< 5"]) if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0')

# loads platform specific gems like ffi, win32 platform gems
# as additional runtime dependencies
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'puppet/version'

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("1.9.3")
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new("1.9.3")
raise LoadError, "Puppet #{Puppet.version} requires ruby 1.9.3 or greater."
end

Expand Down Expand Up @@ -164,7 +164,7 @@ def self.run_mode

# Now that settings are loaded we have the code loaded to be able to issue
# deprecation warnings. Warn if we're on a deprecated ruby version.
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new(Puppet::OLDEST_RECOMMENDED_RUBY_VERSION)
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new(Puppet::OLDEST_RECOMMENDED_RUBY_VERSION)
Puppet.deprecation_warning("Support for ruby version #{RUBY_VERSION} is deprecated and will be removed in a future release. See https://docs.puppet.com/puppet/latest/system_requirements.html#ruby for a list of supported ruby versions.")
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/pops/types/string_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ def string_PRegexpType(val_type, val, format_map, _)
case f.format
when :p
rx_s = val.options == 0 ? val.source : val.to_s
rx_s = rx_s.gsub(/\//, '\/') unless Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0')
rx_s = rx_s.gsub(/\//, '\/') unless Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
str_regexp = "/#{rx_s}/"
f.orig_fmt == '%p' ? str_regexp : Kernel.format(f.orig_fmt.gsub('p', 's'), str_regexp)
when :s
Expand Down

0 comments on commit fb9995d

Please sign in to comment.