json 1.4.5-java → 1.4.6-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.
- data/lib/json/ext/generator.jar +0 -0
- data/lib/json/ext/parser.jar +0 -0
- data/lib/json/pure/generator.rb +57 -75
- data/lib/json/version.rb +1 -1
- data/tests/test_json_generate.rb +14 -0
- metadata +3 -3
data/lib/json/ext/generator.jar
CHANGED
Binary file
|
data/lib/json/ext/parser.jar
CHANGED
Binary file
|
data/lib/json/pure/generator.rb
CHANGED
@@ -112,7 +112,7 @@ module JSON
|
|
112
112
|
when Hash
|
113
113
|
new(opts)
|
114
114
|
else
|
115
|
-
SAFE_STATE_PROTOTYPE
|
115
|
+
SAFE_STATE_PROTOTYPE.dup
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -167,7 +167,7 @@ module JSON
|
|
167
167
|
# generated JSON.
|
168
168
|
attr_accessor :depth
|
169
169
|
|
170
|
-
def check_max_nesting
|
170
|
+
def check_max_nesting # :nodoc:
|
171
171
|
return if @max_nesting.zero?
|
172
172
|
current_nesting = depth + 1
|
173
173
|
current_nesting > @max_nesting and
|
@@ -252,51 +252,41 @@ module JSON
|
|
252
252
|
# _state_ is a JSON::State object, that can also be used to configure the
|
253
253
|
# produced JSON string output further.
|
254
254
|
# _depth_ is used to find out nesting depth, to indent accordingly.
|
255
|
-
def to_json(state = nil,
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
end
|
260
|
-
json_transform(state, depth)
|
255
|
+
def to_json(state = nil, *)
|
256
|
+
state = State.from_state(state)
|
257
|
+
state.check_max_nesting
|
258
|
+
json_transform(state)
|
261
259
|
end
|
262
260
|
|
263
261
|
private
|
264
262
|
|
265
|
-
def json_shift(state
|
266
|
-
state
|
267
|
-
state.indent * depth
|
263
|
+
def json_shift(state)
|
264
|
+
state.object_nl.empty? or return ''
|
265
|
+
state.indent * state.depth
|
268
266
|
end
|
269
267
|
|
270
|
-
def json_transform(state
|
268
|
+
def json_transform(state)
|
271
269
|
delim = ','
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
result << '}'
|
293
|
-
else
|
294
|
-
result = '{'
|
295
|
-
result << map { |key,value|
|
296
|
-
key.to_s.to_json << ':' << value.to_json
|
297
|
-
}.join(delim)
|
298
|
-
result << '}'
|
299
|
-
end
|
270
|
+
delim << state.object_nl
|
271
|
+
result = '{'
|
272
|
+
result << state.object_nl
|
273
|
+
depth = state.depth += 1
|
274
|
+
first = true
|
275
|
+
indent = !state.object_nl.empty?
|
276
|
+
each { |key,value|
|
277
|
+
result << delim unless first
|
278
|
+
result << state.indent * depth if indent
|
279
|
+
result << key.to_s.to_json(state)
|
280
|
+
result << state.space_before
|
281
|
+
result << ':'
|
282
|
+
result << state.space
|
283
|
+
result << value.to_json(state)
|
284
|
+
first = false
|
285
|
+
}
|
286
|
+
depth = state.depth -= 1
|
287
|
+
result << state.object_nl
|
288
|
+
result << state.indent * depth if indent if indent
|
289
|
+
result << '}'
|
300
290
|
result
|
301
291
|
end
|
302
292
|
end
|
@@ -306,39 +296,32 @@ module JSON
|
|
306
296
|
# this Array instance.
|
307
297
|
# _state_ is a JSON::State object, that can also be used to configure the
|
308
298
|
# produced JSON string output further.
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
state.check_max_nesting(depth)
|
314
|
-
end
|
315
|
-
json_transform(state, depth)
|
299
|
+
def to_json(state = nil, *)
|
300
|
+
state = State.from_state(state)
|
301
|
+
state.check_max_nesting
|
302
|
+
json_transform(state)
|
316
303
|
end
|
317
304
|
|
318
305
|
private
|
319
306
|
|
320
|
-
def json_transform(state
|
307
|
+
def json_transform(state)
|
321
308
|
delim = ','
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
result << delim unless first
|
331
|
-
result << state.indent * depth if indent
|
332
|
-
result << value.to_json(state, depth)
|
333
|
-
first = false
|
334
|
-
}
|
335
|
-
depth -= 1
|
336
|
-
result << state.array_nl
|
309
|
+
delim << state.array_nl
|
310
|
+
result = '['
|
311
|
+
result << state.array_nl
|
312
|
+
depth = state.depth += 1
|
313
|
+
first = true
|
314
|
+
indent = !state.array_nl.empty?
|
315
|
+
each { |value|
|
316
|
+
result << delim unless first
|
337
317
|
result << state.indent * depth if indent
|
338
|
-
result <<
|
339
|
-
|
340
|
-
|
341
|
-
|
318
|
+
result << value.to_json(state)
|
319
|
+
first = false
|
320
|
+
}
|
321
|
+
depth = state.depth -= 1
|
322
|
+
result << state.array_nl
|
323
|
+
result << state.indent * depth if indent
|
324
|
+
result << ']'
|
342
325
|
end
|
343
326
|
end
|
344
327
|
|
@@ -350,15 +333,16 @@ module JSON
|
|
350
333
|
module Float
|
351
334
|
# Returns a JSON string representation for this Float number.
|
352
335
|
def to_json(state = nil, *)
|
336
|
+
state = State.from_state(state)
|
353
337
|
case
|
354
338
|
when infinite?
|
355
|
-
if state
|
339
|
+
if state.allow_nan?
|
356
340
|
to_s
|
357
341
|
else
|
358
342
|
raise GeneratorError, "#{self} not allowed in JSON"
|
359
343
|
end
|
360
344
|
when nan?
|
361
|
-
if state
|
345
|
+
if state.allow_nan?
|
362
346
|
to_s
|
363
347
|
else
|
364
348
|
raise GeneratorError, "#{self} not allowed in JSON"
|
@@ -374,9 +358,8 @@ module JSON
|
|
374
358
|
# This string should be encoded with UTF-8 A call to this method
|
375
359
|
# returns a JSON string encoded with UTF16 big endian characters as
|
376
360
|
# \u????.
|
377
|
-
def to_json(*args)
|
378
|
-
state
|
379
|
-
state ||= State.from_state(state)
|
361
|
+
def to_json(state = nil, *args)
|
362
|
+
state = State.from_state(state)
|
380
363
|
if encoding == ::Encoding::UTF_8
|
381
364
|
string = self
|
382
365
|
else
|
@@ -392,9 +375,8 @@ module JSON
|
|
392
375
|
# This string should be encoded with UTF-8 A call to this method
|
393
376
|
# returns a JSON string encoded with UTF16 big endian characters as
|
394
377
|
# \u????.
|
395
|
-
def to_json(*args)
|
396
|
-
state
|
397
|
-
state ||= State.from_state(state)
|
378
|
+
def to_json(state = nil, *args)
|
379
|
+
state = State.from_state(state)
|
398
380
|
if state.ascii_only?
|
399
381
|
'"' << JSON.utf8_to_json_ascii(self) << '"'
|
400
382
|
else
|
data/lib/json/version.rb
CHANGED
data/tests/test_json_generate.rb
CHANGED
@@ -164,4 +164,18 @@ EOT
|
|
164
164
|
assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) }
|
165
165
|
assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true)
|
166
166
|
end
|
167
|
+
|
168
|
+
def test_depth
|
169
|
+
ary = []; ary << ary
|
170
|
+
assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth
|
171
|
+
assert_raises(JSON::NestingError) { JSON.generate(ary) }
|
172
|
+
assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth
|
173
|
+
assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth
|
174
|
+
assert_raises(JSON::NestingError) { JSON.pretty_generate(ary) }
|
175
|
+
assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth
|
176
|
+
s = JSON.state.new
|
177
|
+
assert_equal 0, s.depth
|
178
|
+
assert_raises(JSON::NestingError) { ary.to_json(s) }
|
179
|
+
assert_equal 19, s.depth
|
180
|
+
end
|
167
181
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 1.4.
|
8
|
+
- 6
|
9
|
+
version: 1.4.6
|
10
10
|
platform: java
|
11
11
|
authors:
|
12
12
|
- Daniel Luz
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-12 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|