diff options
author | Samuel Giddins <[email protected]> | 2023-08-23 20:46:14 -0700 |
---|---|---|
committer | git <[email protected]> | 2023-09-20 02:03:03 +0000 |
commit | c65c88e65c0d1c175dd2c33708b488e3f8268fda (patch) | |
tree | db17f99ef925a9d0c5038c00640536bac2d7be25 | |
parent | d3628e6ac4ac4703c88c594af649773205722287 (diff) |
[rubygems/rubygems] Tests passing on truffleruby 22 in addition to 23
https://github.com/rubygems/rubygems/commit/8065530d43
-rw-r--r-- | lib/rubygems/safe_marshal/visitors/to_ruby.rb | 23 | ||||
-rw-r--r-- | test/rubygems/test_gem_safe_marshal.rb | 5 |
2 files changed, 22 insertions, 6 deletions
diff --git a/lib/rubygems/safe_marshal/visitors/to_ruby.rb b/lib/rubygems/safe_marshal/visitors/to_ruby.rb index 92b647438b..81c5c536d5 100644 --- a/lib/rubygems/safe_marshal/visitors/to_ruby.rb +++ b/lib/rubygems/safe_marshal/visitors/to_ruby.rb @@ -89,7 +89,11 @@ module Gem::SafeMarshal nano = Rational(nano_num, nano_den * 1_000_000_000) object = Time.at(object.to_i + nano + object.subsec) elsif RUBY_ENGINE == "truffleruby" - object = Time.at(object.to_i, Rational(nano_num, nano_den).to_i, :nanosecond) + if RUBY_ENGINE_VERSION >= "23.0.0" + object = Time.at(object.to_i, Rational(nano_num, nano_den).to_i, :nanosecond) + else + object = object.floor + Rational(nano_num, nano_den * 1_000_000_000) + end else # assume "ruby" nano = Rational(nano_num, nano_den) nsec, subnano = nano.divmod(1) @@ -106,12 +110,19 @@ module Gem::SafeMarshal object = object.localtime offset end + if RUBY_ENGINE == "truffleruby" && RUBY_ENGINE_VERSION < "23.0.0" + ivars << [:@offset, offset] + ivars << [:@zone, zone] + ivars << [:@nano_num, nano_num] if nano_num + ivars << [:@nano_den, nano_den] if nano_den + end + @objects[object_offset] = object end when Elements::String enc = nil - ivars.each do |k, v| + ivars.reject! do |k, v| case k when :E case v @@ -119,17 +130,19 @@ module Gem::SafeMarshal enc = "UTF-8" when FalseClass enc = "US-ASCII" + else + enc = v end else - break + next false end - idx += 1 + true end object.replace ::String.new(object, encoding: enc) end - ivars[idx..].each do |k, v| + ivars.each do |k, v| object.instance_variable_set k, v end object diff --git a/test/rubygems/test_gem_safe_marshal.rb b/test/rubygems/test_gem_safe_marshal.rb index d9c430bc70..8b6ef5d186 100644 --- a/test/rubygems/test_gem_safe_marshal.rb +++ b/test/rubygems/test_gem_safe_marshal.rb @@ -77,7 +77,10 @@ class TestGemSafeMarshal < Gem::TestCase Time.at(secs, 1.00001, :nanosecond), ].each_with_index do |t, i| define_method("test_time_#{i} #{t.inspect}") do - assert_safe_load_as t, additional_methods: [:ctime, :to_f, :to_r, :to_i, :zone, :subsec, :instance_variables, :dst?, :to_a] + pend "Marshal.load of Time with custom zone is broken before Truffleruby 23" if t.zone.nil? && RUBY_ENGINE == "truffleruby" && RUBY_ENGINE_VERSION < "23" + + additional_methods = [:ctime, :to_f, :to_r, :to_i, :zone, :subsec, :instance_variables, :dst?, :to_a] + assert_safe_load_as t, additional_methods: additional_methods end end |