json 2.7.4-java → 2.7.6-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f61f1f7cf84e855d4f7a7b56d7a1ec807bf1f6f0ba418984b94191bbd15a8db1
4
- data.tar.gz: b81dba38d7eb8dc893cb8107dcc42e829b9b21d0595bdd660f3203db607522cd
3
+ metadata.gz: bc7f91e45f97a190ae906fd62628096c4ca094ce9594fb847e4c85805f7b77a8
4
+ data.tar.gz: b7ef29eec1f9ef2aabecbe36d93efe0011356f030fc5ebc9daf6af0e2b2ab06d
5
5
  SHA512:
6
- metadata.gz: 97ef406dd7d1506134ee9d87d7eec34cbf5377d2485ffb975d3262731bb65ea3370098cd395df07bd1ce96a0adad7b79f312666142f9216b5c31899df640768c
7
- data.tar.gz: aa59a3978e28cda2f8a62b7b51dc3a8dbb39b4dc68a32789f457824e3fb749326635536ff2dcb30b8a70b6591d08bfb041d2ca4e93446e3e4e77a2a441ee0783
6
+ metadata.gz: 1e9788d9a961fc4778bbf0c23fd29fa3f99357652c51e6377479238c9e15ab7bbf628e9f2d4a2255417fdf1ef341c8882c9bc81babdb85458038573bd3f79173
7
+ data.tar.gz: 26e5c02ca4ea4882b0c58b41eb23a53a8ba101625ed0b8bc444f21af50248c1ef185667c47b9c2f50433e335c135792709af8cf601af4e82bc92eb30f18962a6
data/CHANGES.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changes
2
2
 
3
+ ### 2024-11-04 (2.7.6)
4
+
5
+ * Fix a regression in JSON.generate when dealing with Hash keys that are string subclasses, call `to_json` on them.
6
+
7
+ ### 2024-10-25 (2.7.5)
8
+
9
+ * Fix a memory leak when `#to_json` methods raise an exception.
10
+ * Gracefully handle formatting configs being set to `nil` instead of `""`.
11
+ * Workaround another issue caused by conflicting versions of both `json_pure` and `json` being loaded.
12
+
3
13
  ### 2024-10-25 (2.7.4)
4
14
 
5
15
  * Workaround a bug in 3.4.8 and older https://github.com/rubygems/rubygems/pull/6490.
data/lib/json/common.rb CHANGED
@@ -219,7 +219,12 @@ module JSON
219
219
  if opts.nil?
220
220
  Parser.new(source).parse
221
221
  else
222
- Parser.new(source, opts).parse
222
+ # NB: The ** shouldn't be required, but we have to deal with
223
+ # different versions of the `json` and `json_pure` gems being
224
+ # loaded concurrently.
225
+ # Prior to 2.7.3, `JSON::Ext::Parser` would only take kwargs.
226
+ # Ref: https://github.com/ruby/json/issues/650
227
+ Parser.new(source, **opts).parse
223
228
  end
224
229
  end
225
230
 
@@ -46,15 +46,15 @@ module JSON
46
46
  opts.each do |key, value|
47
47
  case key
48
48
  when :indent
49
- self.indent = value
49
+ self.indent = value || ''
50
50
  when :space
51
- self.space = value
51
+ self.space = value || ''
52
52
  when :space_before
53
- self.space_before = value
53
+ self.space_before = value || ''
54
54
  when :array_nl
55
- self.array_nl = value
55
+ self.array_nl = value || ''
56
56
  when :object_nl
57
- self.object_nl = value
57
+ self.object_nl = value || ''
58
58
  when :max_nesting
59
59
  self.max_nesting = value || 0
60
60
  when :depth
@@ -239,13 +239,13 @@ module JSON
239
239
  end
240
240
 
241
241
  # NOTE: If adding new instance variables here, check whether #generate should check them for #generate_json
242
- @indent = opts[:indent] if opts.key?(:indent)
243
- @space = opts[:space] if opts.key?(:space)
244
- @space_before = opts[:space_before] if opts.key?(:space_before)
245
- @object_nl = opts[:object_nl] if opts.key?(:object_nl)
246
- @array_nl = opts[:array_nl] if opts.key?(:array_nl)
247
- @allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan)
248
- @ascii_only = opts[:ascii_only] if opts.key?(:ascii_only)
242
+ @indent = opts[:indent] || '' if opts.key?(:indent)
243
+ @space = opts[:space] || '' if opts.key?(:space)
244
+ @space_before = opts[:space_before] || '' if opts.key?(:space_before)
245
+ @object_nl = opts[:object_nl] || '' if opts.key?(:object_nl)
246
+ @array_nl = opts[:array_nl] || '' if opts.key?(:array_nl)
247
+ @allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan)
248
+ @ascii_only = opts[:ascii_only] if opts.key?(:ascii_only)
249
249
  @depth = opts[:depth] || 0
250
250
  @buffer_initial_length ||= opts[:buffer_initial_length]
251
251
 
@@ -301,19 +301,30 @@ module JSON
301
301
 
302
302
  # Handles @allow_nan, @buffer_initial_length, other ivars must be the default value (see above)
303
303
  private def generate_json(obj, buf)
304
- case obj
305
- when Hash
304
+ klass = obj.class
305
+ if klass == Hash
306
306
  buf << '{'
307
307
  first = true
308
308
  obj.each_pair do |k,v|
309
309
  buf << ',' unless first
310
- fast_serialize_string(k.to_s, buf)
310
+
311
+ key_str = k.to_s
312
+ if key_str.is_a?(::String)
313
+ if key_str.class == ::String
314
+ fast_serialize_string(key_str, buf)
315
+ else
316
+ generate_json(key_str, buf)
317
+ end
318
+ else
319
+ raise TypeError, "#{k.class}#to_s returns an instance of #{key_str.class}, expected a String"
320
+ end
321
+
311
322
  buf << ':'
312
323
  generate_json(v, buf)
313
324
  first = false
314
325
  end
315
326
  buf << '}'
316
- when Array
327
+ elsif klass == Array
317
328
  buf << '['
318
329
  first = true
319
330
  obj.each do |e|
@@ -322,9 +333,9 @@ module JSON
322
333
  first = false
323
334
  end
324
335
  buf << ']'
325
- when String
336
+ elsif klass == String
326
337
  fast_serialize_string(obj, buf)
327
- when Integer
338
+ elsif klass == Integer
328
339
  buf << obj.to_s
329
340
  else
330
341
  # Note: Float is handled this way since Float#to_s is slow anyway
@@ -414,7 +425,15 @@ module JSON
414
425
  each { |key, value|
415
426
  result << delim unless first
416
427
  result << state.indent * depth if indent
417
- result = +"#{result}#{key.to_s.to_json(state)}#{state.space_before}:#{state.space}"
428
+
429
+ key_str = key.to_s
430
+ key_json = if key_str.is_a?(::String)
431
+ key_str = key_str.to_json(state)
432
+ else
433
+ raise TypeError, "#{key.class}#to_s returns an instance of #{key_str.class}, expected a String"
434
+ end
435
+
436
+ result = +"#{result}#{key_json}#{state.space_before}:#{state.space}"
418
437
  if state.strict? && !(false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value)
419
438
  raise GeneratorError, "#{value.class} not allowed in JSON"
420
439
  elsif value.respond_to?(:to_json)
data/lib/json/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSON
4
- VERSION = '2.7.4'
4
+ VERSION = '2.7.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.4
4
+ version: 2.7.6
5
5
  platform: java
6
6
  authors:
7
7
  - Daniel Luz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-25 00:00:00.000000000 Z
11
+ date: 2024-11-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A JSON implementation as a JRuby extension.
14
14
  email: dev+ruby@mernen.com