json 2.19.9-java → 2.21.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f868e8b079bbfd0c07f55ec36c9d2ce852e63bab1b5095053744297e25cff251
4
- data.tar.gz: 0c91a99e820eb62b0efddd05bd400af34139123d61852504884472080d635d1e
3
+ metadata.gz: 1afa1e3890c8c870016c243fc967533cb0a0ef3061e95d6ba29262c7564809b9
4
+ data.tar.gz: f8123182d86d00979ae0fadf3df150b7a2766e5e92a9323d97550ac13bd85769
5
5
  SHA512:
6
- metadata.gz: 7f8d242f8dd44d94b1975f22c8684962d85608da1a660632792b40a32675e16588ed8ac21b16caba7a0822bb1015e2a2b54d524199cc8fb43ae455329c0fef97
7
- data.tar.gz: 9a9ecc0b75fbdd1bc1b579d0913737d49a0abbd87ceb9ebbc26af1f15d0e8053e76cfbe735d44828b1caff4a765172cfdabcd4cbd1846d7563beab8ec3f4a00a
6
+ metadata.gz: 83be4643e044a17198169036eb49eb2ae2dced41f26fe26335cd1feef90acb9b7c56be5a6a986de25dcde2f919a5d587c208f477e65d41783d347f84bf0fdeed
7
+ data.tar.gz: d748f91e351cea5fc38a02c174ca8909bc31e4ef0b611e409936a0248429040e7a70daf6fcdca9781c0fe99a41558ff021dbf127098fb65bbddb4c6853a6a0b0
data/CHANGES.md CHANGED
@@ -2,10 +2,28 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### 2026-07-12 (2.21.0)
6
+
7
+ * `JSON.generate` now accept a `sort_keys` option, which takes either a boolean or a block.
8
+ * Added `#empty?` and `#partial_value?` methods on `JSON::ResumableParser`.
9
+ * Numerous correctness and performance fixes for `JSON::ResumableParser`.
10
+ * Avoid triggering Ruby's `float out of range` warning when parsing out of range numbers.
11
+ * Declare C types with Ruby 4.1 `RUBY_TYPED_THREAD_SAFE_FREE`.
12
+
13
+ ### 2026-06-23 (2.20.0)
14
+
15
+ * Both C and Java parsers are no longer recursive, so parsing very deep documents with `max_nesting: false` will no longer
16
+ result in `SystemStackError stack level too deep` errors.
17
+ * The `:max_nesting` option still defaults to `100`.
18
+ * Optimized floating point number parsing further by replacing the ryu algorithm by a port of Eisel-Lemire Fast Float.
19
+ * Added `JSON::ResumableParser` to parse streams of JSON documents. Not yet available on JRuby.
20
+ * Deprecate default support of JavaScript comments in the parser and add `allow_comments: true` parsing option.
21
+ * Integrate with Ruby 4.1 `ruby_sized_xfree`.
22
+
5
23
  ### 2026-06-11 (2.19.9)
6
24
 
7
25
  * Fix buffer overflow that could lead to a crash when writing JSON directly into an IO
8
- with `JSON.generate(object, io)`. [CVE-PENDING].
26
+ with `JSON.generate(object, io)`. [CVE-2026-54696].
9
27
 
10
28
  ### 2026-06-03 (2.19.8)
11
29
 
data/LEGAL CHANGED
@@ -15,6 +15,6 @@ ext/json/ext/vendor/jeaiii-ltoa.h::
15
15
  This file is adapted from https://github.com/jeaiii/itoa
16
16
  It is licensed under the MIT License
17
17
 
18
- ext/json/ext/vendor/ryu.h::
19
- This file is adapted from the Ryu algorithm by Ulf Adams https://github.com/ulfjack/ryu.
20
- It is dual-licensed under Apache License 2.0 OR Boost Software License 1.0.
18
+ ext/json/ext/vendor/fast_float_parser.h::
19
+ This file is adapted from the Fast Float C++ library by The fast_float authors https://github.com/fastfloat/fast_float
20
+ It is licensed under the MIT License
data/README.md CHANGED
@@ -85,7 +85,7 @@ Both of these behavior can be disabled using the `strict: true` option:
85
85
 
86
86
  ```ruby
87
87
  JSON.generate(Object.new, strict: true) # => Object not allowed in JSON (JSON::GeneratorError)
88
- JSON.generate(Position.new(1, 2)) # => Position not allowed in JSON (JSON::GeneratorError)
88
+ JSON.generate(Position.new(1, 2), strict: true) # => Position not allowed in JSON (JSON::GeneratorError)
89
89
  ```
90
90
 
91
91
  ## JSON::Coder
@@ -117,13 +117,13 @@ It is also called for objects that do have a JSON equivalent, but are used as Ha
117
117
  as well as for strings that aren't valid UTF-8:
118
118
 
119
119
  ```ruby
120
- coder = JSON::Combining.new do |object, is_object_key|
120
+ coder = JSON::Coder.new do |object, is_object_key|
121
121
  case object
122
122
  when String
123
- if !string.valid_encoding? || string.encoding != Encoding::UTF_8
124
- Base64.encode64(string)
123
+ if !object.valid_encoding? || object.encoding != Encoding::UTF_8
124
+ Base64.encode64(object)
125
125
  else
126
- string
126
+ object
127
127
  end
128
128
  else
129
129
  object
@@ -306,5 +306,3 @@ The latest version of this library can be downloaded at
306
306
  Online Documentation should be located at
307
307
 
308
308
  * https://www.rubydoc.info/gems/json
309
-
310
- [Ragel]: http://www.colm.net/open-source/ragel/
data/lib/json/common.rb CHANGED
@@ -155,6 +155,15 @@ module JSON
155
155
  # Set the module _generator_ to be used by JSON.
156
156
  def generator=(generator) # :nodoc:
157
157
  old, $VERBOSE = $VERBOSE, nil
158
+
159
+ # The default proc used when the +sort_keys+ generation option is +true+.
160
+ # It returns a new hash with the entries sorted by their keys.
161
+ sort_keys_proc = ->(hash) { hash.sort.to_h }
162
+ if defined?(::Ractor) && Ractor.respond_to?(:shareable_lambda)
163
+ sort_keys_proc = Ractor.shareable_lambda(&sort_keys_proc)
164
+ end
165
+ generator::State.default_sort_keys_proc = sort_keys_proc
166
+
158
167
  @generator = generator
159
168
  if generator.const_defined?(:GeneratorMethods)
160
169
  generator_methods = generator::GeneratorMethods
@@ -54,6 +54,7 @@ module JSON
54
54
  strict: strict?,
55
55
  depth: depth,
56
56
  buffer_initial_length: buffer_initial_length,
57
+ sort_keys: sort_keys
57
58
  }
58
59
 
59
60
  allow_duplicate_key = allow_duplicate_key?
Binary file
Binary file
data/lib/json/ext.rb CHANGED
@@ -41,5 +41,31 @@ module JSON
41
41
  end
42
42
  end
43
43
 
44
+ if defined?(ResumableParser) # Not yet available on JRuby
45
+ class ResumableParser
46
+ # Returns whether the parser is entirely done: no unconsumed bytes in
47
+ # the buffer, no document under construction and no parsed value
48
+ # awaiting retrieval.
49
+ #
50
+ # The main use case is detecting a truncated stream once the input is
51
+ # exhausted:
52
+ #
53
+ # loop do
54
+ # begin
55
+ # parser << socket.readpartial(4096)
56
+ # rescue EOFError
57
+ # break
58
+ # end
59
+ # while parser.parse
60
+ # process(parser.value)
61
+ # end
62
+ # end
63
+ # warn "stream was truncated" unless parser.empty?
64
+ def empty?
65
+ eos? && !partial_value? && !value?
66
+ end
67
+ end
68
+ end
69
+
44
70
  JSON_LOADED = true unless defined?(JSON::JSON_LOADED)
45
71
  end
@@ -111,6 +111,8 @@ module JSON
111
111
  # This class is used to create State instances, that are use to hold data
112
112
  # while generating a JSON text from a Ruby data structure.
113
113
  class State
114
+ singleton_class.attr_accessor :default_sort_keys_proc # :nodoc:
115
+
114
116
  def self.generate(obj, opts = nil, io = nil)
115
117
  new(opts).generate(obj, io)
116
118
  end
@@ -164,6 +166,7 @@ module JSON
164
166
  @script_safe = false
165
167
  @strict = false
166
168
  @max_nesting = 100
169
+ @sort_keys = false
167
170
  configure(opts) if opts
168
171
  end
169
172
 
@@ -199,6 +202,33 @@ module JSON
199
202
  # supported by the JSON spec will raise a JSON::GeneratorError
200
203
  attr_accessor :strict
201
204
 
205
+ # Controls key sorting in the generated JSON. If set to +true+, object
206
+ # keys are sorted by key lexicographically. If set to a Proc, it
207
+ # receives the entire Hash and must return a Hash with its pairs in the
208
+ # desired order.
209
+ attr_reader :sort_keys
210
+
211
+ def sort_keys=(value) # :nodoc:
212
+ type_error = false
213
+ @sort_keys = case value
214
+ when Proc
215
+ value
216
+ when true
217
+ State.default_sort_keys_proc
218
+ when nil, false
219
+ false
220
+ else
221
+ type_error = true
222
+ false
223
+ end
224
+
225
+ if type_error
226
+ raise TypeError, "The `sort_keys` argument must be a boolean or a Proc"
227
+ end
228
+
229
+ @sort_keys
230
+ end
231
+
202
232
  # :stopdoc:
203
233
  attr_reader :buffer_initial_length
204
234
 
@@ -285,6 +315,7 @@ module JSON
285
315
  @allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan)
286
316
  @as_json = opts[:as_json].to_proc if opts[:as_json]
287
317
  @ascii_only = opts[:ascii_only] if opts.key?(:ascii_only)
318
+ self.sort_keys = opts[:sort_keys] if opts.key?(:sort_keys)
288
319
  @depth = opts[:depth] || 0
289
320
  @buffer_initial_length ||= opts[:buffer_initial_length]
290
321
 
@@ -349,9 +380,13 @@ module JSON
349
380
 
350
381
  depth = @depth
351
382
  if @indent.empty? and @space.empty? and @space_before.empty? and @object_nl.empty? and @array_nl.empty? and
352
- !@ascii_only and !@script_safe and @max_nesting == 0 and (!@strict || Symbol === obj)
383
+ !@ascii_only and !@script_safe and @max_nesting == 0 and (!@strict || Symbol === obj) and !@sort_keys
353
384
  result = generate_json(obj, ''.dup)
354
385
  else
386
+ if @sort_keys
387
+ obj = @sort_keys.call(obj)
388
+ end
389
+
355
390
  result = obj.to_json(self)
356
391
  end
357
392
  JSON::TruffleRuby::Generator.valid_utf8?(result) or raise GeneratorError.new(
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.19.9'
4
+ VERSION = '2.21.0'
5
5
  end
data/lib/json.rb CHANGED
@@ -145,11 +145,11 @@ require 'json/common'
145
145
  # # warning: detected duplicate keys in JSON object.
146
146
  # # This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`
147
147
  #
148
- # When set to `+true+`
148
+ # When set to +true+:
149
149
  # # The last value is used.
150
150
  # JSON.parse('{"a": 1, "a":2}') => {"a" => 2}
151
151
  #
152
- # When set to `+false+`, the future default:
152
+ # When set to +false+, the future default:
153
153
  # JSON.parse('{"a": 1, "a":2}') => duplicate key at line 1 column 1 (JSON::ParserError)
154
154
  #
155
155
  # ---
@@ -184,6 +184,20 @@ require 'json/common'
184
184
  #
185
185
  # ---
186
186
  #
187
+ # Option +allow_comments+ (boolean) specifies whether to allow
188
+ # JavaScript style comments (either <tt>// comment</tt> or <tt>/* comment */</tt>);
189
+ # defaults to +false+.
190
+ #
191
+ # When not specified, a deprecation warning is emitted if a comment is encountered.
192
+ #
193
+ # When set to +true+, comments are ignored:
194
+ # JSON.parse('/* comment */ {"a": 1, "a":2}') # => {"a" => 2}
195
+ #
196
+ # When set to +false+, the future default:
197
+ # JSON.parse('/* comment */ {"a": 1, "a":2}') # unexpected character: '/' at line 1 column 1 (JSON::ParserError)
198
+ #
199
+ # ---
200
+ #
187
201
  # Option +allow_control_characters+ (boolean) specifies whether to allow
188
202
  # unescaped ASCII control characters, such as newlines, in strings;
189
203
  # defaults to +false+.
@@ -394,7 +408,6 @@ require 'json/common'
394
408
  # to be inserted after each \JSON object; defaults to the empty \String, <tt>''</tt>.
395
409
  # - Option +indent+ (\String) specifies the string (usually spaces) to be
396
410
  # used for indentation; defaults to the empty \String, <tt>''</tt>;
397
- # defaults to the empty \String, <tt>''</tt>;
398
411
  # has no effect unless options +array_nl+ or +object_nl+ specify newlines.
399
412
  # - Option +space+ (\String) specifies a string (usually a space) to be
400
413
  # inserted after the colon in each \JSON object's pair;
@@ -402,6 +415,11 @@ require 'json/common'
402
415
  # - Option +space_before+ (\String) specifies a string (usually a space) to be
403
416
  # inserted before the colon in each \JSON object's pair;
404
417
  # defaults to the empty \String, <tt>''</tt>.
418
+ # - Option +sort_keys+ (boolean or \Proc) controls whether and how the keys of a
419
+ # hash are sorted when generating the output; defaults to <tt>false</tt>.
420
+ # When +true+, keys are sorted lexicographically. When a \Proc, it receives
421
+ # the entire \Hash and must return a \Hash with its pairs in the desired
422
+ # order, allowing for arbitrary sort orders.
405
423
  #
406
424
  # In this example, +obj+ is used first to generate the shortest
407
425
  # \JSON data (no whitespace), then again with all formatting options
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.19.9
4
+ version: 2.21.0
5
5
  platform: java
6
6
  authors:
7
7
  - Daniel Luz
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-06-11 00:00:00.000000000 Z
10
+ date: 2026-07-12 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: A JSON implementation as a JRuby extension.
13
13
  email: dev+ruby@mernen.com