Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Marshaling a time object added an instance variable to the object whi…

…ch affected the quoting of serialized attributes because the to_yaml of the original object did not match the to_yaml of the marshaled one. Also, Marshal.dump was modifying the source object which the client may not be aware of.

Signed-off-by: wycats <wycats@gmail.com>
  • Loading branch information...
commit c1b22000856412eb0f5966e9e2fbcc4d91b60208 1 parent 157c180
@jrafanie jrafanie authored wycats committed
View
4 activesupport/lib/active_support/core_ext/time.rb
@@ -15,14 +15,14 @@ class << self
alias_method :_original_load, :_load
def _load(marshaled_time)
time = _original_load(marshaled_time)
- utc = time.instance_variable_get('@marshal_with_utc_coercion')
+ utc = time.send(:remove_instance_variable, '@marshal_with_utc_coercion') if time.instance_variable_defined?('@marshal_with_utc_coercion')
utc ? time.utc : time
end
end
alias_method :_original_dump, :_dump
def _dump(*args)
- obj = self.frozen? ? self.dup : self
+ obj = self.dup
obj.instance_variable_set('@marshal_with_utc_coercion', utc?)
obj._original_dump(*args)
end
View
15 activesupport/test/core_ext/time_ext_test.rb
@@ -745,4 +745,19 @@ def test_marshaling_with_frozen_local_instance
assert_equal t, unmarshaled
assert_equal t.zone, unmarshaled.zone
end
+
+ def test_marshaling_does_not_modify_source_object
+ t = Time.local(2000)
+ Marshal.dump t
+ assert_equal false, t.instance_variable_defined?('@marshal_with_utc_coercion')
+ end
+
+ def test_marshaling_does_not_affect_yaml_dump
+ t = Time.local(2000)
+ t2 = t.dup
+ marshaled = Marshal.dump t2
+ unmarshaled = Marshal.load marshaled
+ assert_equal t.to_yaml, unmarshaled.to_yaml
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.