Skip to content
This repository
Browse code

Fix TimeWithZone unmarshaling: coerce unmarshaled Time instances to u…

…tc, because Ruby's marshaling of Time instances doesn't respect the zone
  • Loading branch information...
commit 34510456585216004e483b79beeea3ddc3eb4de6 1 parent 7f03462
Geoff Buesing gbuesing authored
2  activesupport/CHANGELOG
... ... @@ -1,5 +1,7 @@
1 1 *Edge*
2 2
  3 +* Fix TimeWithZone unmarshaling: coerce unmarshaled Time instances to utc, because Ruby's marshaling of Time instances doesn't respect the zone [Geoff Buesing]
  4 +
3 5 * Added Memoizable mixin for caching simple lazy loaded attributes [Josh Peek]
4 6
5 7 * Move the test related core_ext stuff out of core_ext so it's only loaded by the test helpers. [Michael Koziarski]
2  activesupport/lib/active_support/time_with_zone.rb
@@ -263,7 +263,7 @@ def marshal_dump
263 263 end
264 264
265 265 def marshal_load(variables)
266   - initialize(variables[0], ::Time.send!(:get_zone, variables[1]), variables[2])
  266 + initialize(variables[0].utc, ::Time.send!(:get_zone, variables[1]), variables[2].utc)
267 267 end
268 268
269 269 # Ensure proxy class responds to all methods that underlying time instance responds to.
6 activesupport/test/core_ext/time_with_zone_test.rb
@@ -320,8 +320,11 @@ def test_marshal_dump_and_load
320 320 marshal_str = Marshal.dump(@twz)
321 321 mtime = Marshal.load(marshal_str)
322 322 assert_equal Time.utc(2000, 1, 1, 0), mtime.utc
  323 + assert mtime.utc.utc?
323 324 assert_equal ActiveSupport::TimeZone['Eastern Time (US & Canada)'], mtime.time_zone
324 325 assert_equal Time.utc(1999, 12, 31, 19), mtime.time
  326 + assert mtime.time.utc?
  327 + assert_equal @twz.inspect, mtime.inspect
325 328 end
326 329 end
327 330
@@ -331,8 +334,11 @@ def test_marshal_dump_and_load_with_tzinfo_identifier
331 334 marshal_str = Marshal.dump(twz)
332 335 mtime = Marshal.load(marshal_str)
333 336 assert_equal Time.utc(2000, 1, 1, 0), mtime.utc
  337 + assert mtime.utc.utc?
334 338 assert_equal 'America/New_York', mtime.time_zone.name
335 339 assert_equal Time.utc(1999, 12, 31, 19), mtime.time
  340 + assert mtime.time.utc?
  341 + assert_equal @twz.inspect, mtime.inspect
336 342 end
337 343 end
338 344

0 comments on commit 3451045

Please sign in to comment.
Something went wrong with that request. Please try again.