json 1.5.4-java → 1.5.5-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of json might be problematic. Click here for more details.

@@ -36,8 +36,8 @@ class Time
36
36
  if usec = object.delete('u') # used to be tv_usec -> tv_nsec
37
37
  object['n'] = usec * 1000
38
38
  end
39
- if respond_to?(:tv_nsec)
40
- at(*object.values_at('s', 'n'))
39
+ if instance_methods.include?(:tv_nsec)
40
+ at(object['s'], Rational(object['n'], 1000))
41
41
  else
42
42
  at(object['s'], object['n'] / 1000)
43
43
  end
@@ -46,10 +46,13 @@ class Time
46
46
  # Returns a hash, that will be turned into a JSON object and represent this
47
47
  # object.
48
48
  def as_json(*)
49
+ nanoseconds = [ tv_usec * 1000 ]
50
+ respond_to?(:tv_nsec) and nanoseconds << tv_nsec
51
+ nanoseconds = nanoseconds.max
49
52
  {
50
53
  JSON.create_id => self.class.name,
51
54
  's' => tv_sec,
52
- 'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
55
+ 'n' => nanoseconds,
53
56
  }
54
57
  end
55
58
 
@@ -141,7 +141,7 @@ module JSON
141
141
  # the default.
142
142
  # * *create_additions*: If set to false, the Parser doesn't create
143
143
  # additions even if a matching class and create_id was found. This option
144
- # defaults to true.
144
+ # defaults to false.
145
145
  # * *object_class*: Defaults to Hash
146
146
  # * *array_class*: Defaults to Array
147
147
  def parse(source, opts = {})
@@ -162,7 +162,7 @@ module JSON
162
162
  # to true.
163
163
  # * *create_additions*: If set to false, the Parser doesn't create
164
164
  # additions even if a matching class and create_id was found. This option
165
- # defaults to true.
165
+ # defaults to false.
166
166
  def parse!(source, opts = {})
167
167
  opts = {
168
168
  :max_nesting => false,
@@ -287,11 +287,18 @@ module JSON
287
287
  # Load a ruby data structure from a JSON _source_ and return it. A source can
288
288
  # either be a string-like object, an IO-like object, or an object responding
289
289
  # to the read method. If _proc_ was given, it will be called with any nested
290
- # Ruby object as an argument recursively in depth first order.
290
+ # Ruby object as an argument recursively in depth first order. To modify the
291
+ # default options pass in the optional _options_ argument as well.
291
292
  #
292
293
  # This method is part of the implementation of the load/dump interface of
293
294
  # Marshal and YAML.
294
- def load(source, proc = nil)
295
+ def load(source, proc = nil, options = {})
296
+ load_default_options = {
297
+ :max_nesting => false,
298
+ :allow_nan => true,
299
+ :create_additions => false
300
+ }
301
+ opts = load_default_options.merge options
295
302
  if source.respond_to? :to_str
296
303
  source = source.to_str
297
304
  elsif source.respond_to? :to_io
@@ -299,7 +306,7 @@ module JSON
299
306
  else
300
307
  source = source.read
301
308
  end
302
- result = parse(source, :max_nesting => false, :allow_nan => true)
309
+ result = parse(source, opts)
303
310
  recurse_proc(result, &proc) if proc
304
311
  result
305
312
  end
Binary file
Binary file
@@ -63,9 +63,9 @@ module JSON
63
63
  # * *symbolize_names*: If set to true, returns symbols for the names
64
64
  # (keys) in a JSON object. Otherwise strings are returned, which is also
65
65
  # the default.
66
- # * *create_additions*: If set to false, the Parser doesn't create
67
- # additions even if a matchin class and create_id was found. This option
68
- # defaults to true.
66
+ # * *create_additions*: If set to true, the Parser creates
67
+ # additions when if a matching class and create_id was found. This
68
+ # option defaults to false.
69
69
  # * *object_class*: Defaults to Hash
70
70
  # * *array_class*: Defaults to Array
71
71
  # * *quirks_mode*: Enables quirks_mode for parser, that is for example
@@ -88,7 +88,7 @@ module JSON
88
88
  if opts.key?(:create_additions)
89
89
  @create_additions = !!opts[:create_additions]
90
90
  else
91
- @create_additions = true
91
+ @create_additions = false
92
92
  end
93
93
  @create_id = @create_additions ? JSON.create_id : nil
94
94
  @object_class = opts[:object_class] || Hash
@@ -1,6 +1,6 @@
1
1
  module JSON
2
2
  # JSON version
3
- VERSION = '1.5.4'
3
+ VERSION = '1.5.5'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -4,6 +4,7 @@
4
4
  require 'test/unit'
5
5
  require File.join(File.dirname(__FILE__), 'setup_variant')
6
6
  require 'stringio'
7
+ require 'tempfile'
7
8
 
8
9
  unless Array.method_defined?(:permutation)
9
10
  begin
@@ -263,12 +264,12 @@ class TC_JSON < Test::Unit::TestCase
263
264
  def test_generation_of_core_subclasses_with_new_to_json
264
265
  obj = SubHash2["foo" => SubHash2["bar" => true]]
265
266
  obj_json = JSON(obj)
266
- obj_again = JSON(obj_json)
267
+ obj_again = JSON.parse(obj_json, :create_additions => true)
267
268
  assert_kind_of SubHash2, obj_again
268
269
  assert_kind_of SubHash2, obj_again['foo']
269
270
  assert obj_again['foo']['bar']
270
271
  assert_equal obj, obj_again
271
- assert_equal ["foo"], JSON(JSON(SubArray2["foo"]))
272
+ assert_equal ["foo"], JSON(JSON(SubArray2["foo"]), :create_additions => true)
272
273
  end
273
274
 
274
275
  def test_generation_of_core_subclasses_with_default_to_json
@@ -414,6 +415,25 @@ EOT
414
415
  JSON.parse('{"foo":"bar", "baz":"quux"}', :symbolize_names => true))
415
416
  end
416
417
 
418
+ def test_load
419
+ assert_equal @hash, JSON.load(@json)
420
+ tempfile = Tempfile.open('json')
421
+ tempfile.write @json
422
+ tempfile.rewind
423
+ assert_equal @hash, JSON.load(tempfile)
424
+ stringio = StringIO.new(@json)
425
+ stringio.rewind
426
+ assert_equal @hash, JSON.load(stringio)
427
+ assert_raise(NoMethodError) { JSON.load(nil) }
428
+ assert_raise(JSON::ParserError) {JSON.load('') }
429
+ end
430
+
431
+ def test_load_with_options
432
+ small_hash = JSON("foo" => 'bar')
433
+ symbol_hash = { :foo => 'bar' }
434
+ assert_equal symbol_hash, JSON.load(small_hash, nil, :symbolize_names => true)
435
+ end
436
+
417
437
  def test_load_dump
418
438
  too_deep = '[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]'
419
439
  assert_equal too_deep, JSON.dump(eval(too_deep))
@@ -71,11 +71,19 @@ class TC_JSONAddition < Test::Unit::TestCase
71
71
  a = A.new(666)
72
72
  assert A.json_creatable?
73
73
  json = generate(a)
74
- a_again = JSON.parse(json)
74
+ a_again = JSON.parse(json, :create_additions => true)
75
75
  assert_kind_of a.class, a_again
76
76
  assert_equal a, a_again
77
77
  end
78
78
 
79
+ def test_extended_json_default
80
+ a = A.new(666)
81
+ assert A.json_creatable?
82
+ json = generate(a)
83
+ a_hash = JSON.parse(json)
84
+ assert_kind_of Hash, a_hash
85
+ end
86
+
79
87
  def test_extended_json_disabled
80
88
  a = A.new(666)
81
89
  assert A.json_creatable?
@@ -102,7 +110,7 @@ class TC_JSONAddition < Test::Unit::TestCase
102
110
  c = C.new
103
111
  assert !C.json_creatable?
104
112
  json = generate(c)
105
- assert_raises(ArgumentError, NameError) { JSON.parse(json) }
113
+ assert_raises(ArgumentError, NameError) { JSON.parse(json, :create_additions => true) }
106
114
  end
107
115
 
108
116
  def test_raw_strings
@@ -120,7 +128,7 @@ class TC_JSONAddition < Test::Unit::TestCase
120
128
  assert_match(/\A\{.*\}\Z/, json)
121
129
  assert_match(/"json_class":"String"/, json)
122
130
  assert_match(/"raw":\[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255\]/, json)
123
- raw_again = JSON.parse(json)
131
+ raw_again = JSON.parse(json, :create_additions => true)
124
132
  assert_equal raw, raw_again
125
133
  end
126
134
 
@@ -128,17 +136,17 @@ class TC_JSONAddition < Test::Unit::TestCase
128
136
 
129
137
  def test_core
130
138
  t = Time.now
131
- assert_equal t.inspect, JSON(JSON(t)).inspect
139
+ assert_equal t, JSON(JSON(t), :create_additions => true)
132
140
  d = Date.today
133
- assert_equal d, JSON(JSON(d))
141
+ assert_equal d, JSON(JSON(d), :create_additions => true)
134
142
  d = DateTime.civil(2007, 6, 14, 14, 57, 10, Rational(1, 12), 2299161)
135
- assert_equal d, JSON(JSON(d))
136
- assert_equal 1..10, JSON(JSON(1..10))
137
- assert_equal 1...10, JSON(JSON(1...10))
138
- assert_equal "a".."c", JSON(JSON("a".."c"))
139
- assert_equal "a"..."c", JSON(JSON("a"..."c"))
143
+ assert_equal d, JSON(JSON(d), :create_additions => true)
144
+ assert_equal 1..10, JSON(JSON(1..10), :create_additions => true)
145
+ assert_equal 1...10, JSON(JSON(1...10), :create_additions => true)
146
+ assert_equal "a".."c", JSON(JSON("a".."c"), :create_additions => true)
147
+ assert_equal "a"..."c", JSON(JSON("a"..."c"), :create_additions => true)
140
148
  s = MyJsonStruct.new 4711, 'foot'
141
- assert_equal s, JSON(JSON(s))
149
+ assert_equal s, JSON(JSON(s), :create_additions => true)
142
150
  struct = Struct.new :foo, :bar
143
151
  s = struct.new 4711, 'foot'
144
152
  assert_raises(JSONError) { JSON(s) }
@@ -146,29 +154,29 @@ class TC_JSONAddition < Test::Unit::TestCase
146
154
  raise TypeError, "test me"
147
155
  rescue TypeError => e
148
156
  e_json = JSON.generate e
149
- e_again = JSON e_json
157
+ e_again = JSON e_json, :create_additions => true
150
158
  assert_kind_of TypeError, e_again
151
159
  assert_equal e.message, e_again.message
152
160
  assert_equal e.backtrace, e_again.backtrace
153
161
  end
154
- assert_equal(/foo/, JSON(JSON(/foo/)))
155
- assert_equal(/foo/i, JSON(JSON(/foo/i)))
162
+ assert_equal(/foo/, JSON(JSON(/foo/), :create_additions => true))
163
+ assert_equal(/foo/i, JSON(JSON(/foo/i), :create_additions => true))
156
164
  end
157
165
 
158
166
  def test_utc_datetime
159
167
  now = Time.now
160
- d = DateTime.parse(now.to_s) # usual case
161
- assert_equal d, JSON.parse(d.to_json)
168
+ d = DateTime.parse(now.to_s, :create_additions => true) # usual case
169
+ assert_equal d, JSON.parse(d.to_json, :create_additions => true)
162
170
  d = DateTime.parse(now.utc.to_s) # of = 0
163
- assert_equal d, JSON.parse(d.to_json)
171
+ assert_equal d, JSON.parse(d.to_json, :create_additions => true)
164
172
  d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(1,24))
165
- assert_equal d, JSON.parse(d.to_json)
173
+ assert_equal d, JSON.parse(d.to_json, :create_additions => true)
166
174
  d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(12,24))
167
- assert_equal d, JSON.parse(d.to_json)
175
+ assert_equal d, JSON.parse(d.to_json, :create_additions => true)
168
176
  end
169
177
 
170
178
  def test_rational_complex
171
- assert_equal Rational(2, 9), JSON(JSON(Rational(2, 9)))
172
- assert_equal Complex(2, 9), JSON(JSON(Complex(2, 9)))
179
+ assert_equal Rational(2, 9), JSON.parse(JSON(Rational(2, 9)), :create_additions => true)
180
+ assert_equal Complex(2, 9), JSON.parse(JSON(Complex(2, 9)), :create_additions => true)
173
181
  end
174
182
  end
@@ -27,14 +27,13 @@ class TestJsonStringMatching < Test::Unit::TestCase
27
27
  t = TestTime.new
28
28
  t_json = [ t ].to_json
29
29
  assert_equal [ t ],
30
- JSON.parse(t_json,
31
- :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime })
30
+ JSON.parse(t_json, :create_additions => true,
31
+ :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime })
32
32
  assert_equal [ t.strftime('%FT%T%z') ],
33
- JSON.parse(t_json,
34
- :match_string => { /\A\d{3}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime })
33
+ JSON.parse(t_json, :create_additions => true,
34
+ :match_string => { /\A\d{3}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime })
35
35
  assert_equal [ t.strftime('%FT%T%z') ],
36
36
  JSON.parse(t_json,
37
- :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime },
38
- :create_additions => false)
37
+ :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime })
39
38
  end
40
39
  end
metadata CHANGED
@@ -1,114 +1,113 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: json
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.5.4
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.5.5
6
6
  platform: java
7
- authors:
8
- - Daniel Luz
9
- autorequire:
7
+ authors:
8
+ - Daniel Luz
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-08-31 00:00:00 Z
12
+ date: 2013-02-10 00:00:00.000000000 Z
14
13
  dependencies: []
15
-
16
14
  description: A JSON implementation as a JRuby extension.
17
15
  email: dev+ruby@mernen.com
18
16
  executables: []
19
-
20
17
  extensions: []
21
-
22
18
  extra_rdoc_files: []
23
-
24
- files:
25
- - lib/json.rb
26
- - lib/json/Array.xpm
27
- - lib/json/common.rb
28
- - lib/json/editor.rb
29
- - lib/json/ext.rb
30
- - lib/json/FalseClass.xpm
31
- - lib/json/Hash.xpm
32
- - lib/json/json.xpm
33
- - lib/json/Key.xpm
34
- - lib/json/NilClass.xpm
35
- - lib/json/Numeric.xpm
36
- - lib/json/pure.rb
37
- - lib/json/String.xpm
38
- - lib/json/TrueClass.xpm
39
- - lib/json/version.rb
40
- - lib/json/add/complex.rb
41
- - lib/json/add/core.rb
42
- - lib/json/add/rational.rb
43
- - lib/json/ext/generator.jar
44
- - lib/json/ext/parser.jar
45
- - lib/json/pure/generator.rb
46
- - lib/json/pure/parser.rb
47
- - tests/setup_variant.rb
48
- - tests/test_json.rb
49
- - tests/test_json_addition.rb
50
- - tests/test_json_encoding.rb
51
- - tests/test_json_fixtures.rb
52
- - tests/test_json_generate.rb
53
- - tests/test_json_string_matching.rb
54
- - tests/test_json_unicode.rb
55
- - tests/fixtures/fail1.json
56
- - tests/fixtures/fail10.json
57
- - tests/fixtures/fail11.json
58
- - tests/fixtures/fail12.json
59
- - tests/fixtures/fail13.json
60
- - tests/fixtures/fail14.json
61
- - tests/fixtures/fail18.json
62
- - tests/fixtures/fail19.json
63
- - tests/fixtures/fail2.json
64
- - tests/fixtures/fail20.json
65
- - tests/fixtures/fail21.json
66
- - tests/fixtures/fail22.json
67
- - tests/fixtures/fail23.json
68
- - tests/fixtures/fail24.json
69
- - tests/fixtures/fail25.json
70
- - tests/fixtures/fail27.json
71
- - tests/fixtures/fail28.json
72
- - tests/fixtures/fail3.json
73
- - tests/fixtures/fail4.json
74
- - tests/fixtures/fail5.json
75
- - tests/fixtures/fail6.json
76
- - tests/fixtures/fail7.json
77
- - tests/fixtures/fail8.json
78
- - tests/fixtures/fail9.json
79
- - tests/fixtures/pass1.json
80
- - tests/fixtures/pass15.json
81
- - tests/fixtures/pass16.json
82
- - tests/fixtures/pass17.json
83
- - tests/fixtures/pass2.json
84
- - tests/fixtures/pass26.json
85
- - tests/fixtures/pass3.json
19
+ files:
20
+ - lib/json.rb
21
+ - lib/json/json.xpm
22
+ - lib/json/TrueClass.xpm
23
+ - lib/json/version.rb
24
+ - lib/json/Array.xpm
25
+ - lib/json/common.rb
26
+ - lib/json/ext.rb
27
+ - lib/json/pure.rb
28
+ - lib/json/Key.xpm
29
+ - lib/json/FalseClass.xpm
30
+ - lib/json/editor.rb
31
+ - lib/json/Numeric.xpm
32
+ - lib/json/NilClass.xpm
33
+ - lib/json/String.xpm
34
+ - lib/json/Hash.xpm
35
+ - lib/json/add/complex.rb
36
+ - lib/json/add/rational.rb
37
+ - lib/json/add/core.rb
38
+ - lib/json/pure/generator.rb
39
+ - lib/json/pure/parser.rb
40
+ - lib/json/ext/generator.jar
41
+ - lib/json/ext/parser.jar
42
+ - tests/test_json_string_matching.rb
43
+ - tests/test_json_fixtures.rb
44
+ - tests/setup_variant.rb
45
+ - tests/test_json_unicode.rb
46
+ - tests/test_json_addition.rb
47
+ - tests/test_json_generate.rb
48
+ - tests/test_json_encoding.rb
49
+ - tests/test_json.rb
50
+ - tests/fixtures/fail6.json
51
+ - tests/fixtures/fail9.json
52
+ - tests/fixtures/fail10.json
53
+ - tests/fixtures/fail24.json
54
+ - tests/fixtures/fail28.json
55
+ - tests/fixtures/fail13.json
56
+ - tests/fixtures/fail4.json
57
+ - tests/fixtures/pass3.json
58
+ - tests/fixtures/fail11.json
59
+ - tests/fixtures/fail14.json
60
+ - tests/fixtures/fail3.json
61
+ - tests/fixtures/fail12.json
62
+ - tests/fixtures/pass16.json
63
+ - tests/fixtures/pass15.json
64
+ - tests/fixtures/fail20.json
65
+ - tests/fixtures/fail8.json
66
+ - tests/fixtures/pass2.json
67
+ - tests/fixtures/fail5.json
68
+ - tests/fixtures/fail1.json
69
+ - tests/fixtures/fail25.json
70
+ - tests/fixtures/pass17.json
71
+ - tests/fixtures/fail7.json
72
+ - tests/fixtures/pass26.json
73
+ - tests/fixtures/fail21.json
74
+ - tests/fixtures/pass1.json
75
+ - tests/fixtures/fail23.json
76
+ - tests/fixtures/fail18.json
77
+ - tests/fixtures/fail2.json
78
+ - tests/fixtures/fail22.json
79
+ - tests/fixtures/fail27.json
80
+ - tests/fixtures/fail19.json
86
81
  homepage: http://json-jruby.rubyforge.org/
87
82
  licenses: []
88
-
89
- post_install_message:
83
+ post_install_message:
90
84
  rdoc_options: []
91
-
92
- require_paths:
93
- - lib
94
- required_ruby_version: !ruby/object:Gem::Requirement
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ hash: 2
94
+ version: !binary |-
95
+ MA==
95
96
  none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: "0"
100
- required_rubygems_version: !ruby/object:Gem::Requirement
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ segments:
102
+ - 0
103
+ hash: 2
104
+ version: !binary |-
105
+ MA==
101
106
  none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: "0"
106
107
  requirements: []
107
-
108
108
  rubyforge_project: json-jruby
109
- rubygems_version: 1.8.9
110
- signing_key:
109
+ rubygems_version: 1.8.24
110
+ signing_key:
111
111
  specification_version: 3
112
112
  summary: JSON implementation for JRuby
113
113
  test_files: []
114
-