diff options
author | Florian Frank <flori@ping.de> | 2013-02-04 23:28:30 +0100 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2013-02-10 18:21:37 +0100 |
commit | 79fa7f352bae842017c885101a556875600fb468 (patch) | |
tree | cec7e7246b943f3a9eff92a1a54ff8e7088035c5 /lib/json/add | |
parent | 3dab4c5a6a97fac03dacf19446b9ff2a6b397591 (diff) | |
download | json-fix-additions-problem-v1.5.5.tar.gz |
Security fix create_additons problem 1.5.5v1.5.5fix-additions-problem-v1.5.5
Diffstat (limited to 'lib/json/add')
-rw-r--r-- | lib/json/add/core.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/json/add/core.rb b/lib/json/add/core.rb index 1ae00d0..01b8e04 100644 --- a/lib/json/add/core.rb +++ b/lib/json/add/core.rb @@ -36,8 +36,8 @@ class Time if usec = object.delete('u') # used to be tv_usec -> tv_nsec object['n'] = usec * 1000 end - if respond_to?(:tv_nsec) - at(*object.values_at('s', 'n')) + if instance_methods.include?(:tv_nsec) + at(object['s'], Rational(object['n'], 1000)) else at(object['s'], object['n'] / 1000) end @@ -46,10 +46,13 @@ class Time # Returns a hash, that will be turned into a JSON object and represent this # object. def as_json(*) + nanoseconds = [ tv_usec * 1000 ] + respond_to?(:tv_nsec) and nanoseconds << tv_nsec + nanoseconds = nanoseconds.max { JSON.create_id => self.class.name, 's' => tv_sec, - 'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000 + 'n' => nanoseconds, } end |