json 2.15.1-java → 2.16.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: c9c9f896105222f17d7561710f916b6dd6ceb760e3d9ac17a778159954a3cd4d
4
- data.tar.gz: 551c43c7e7f71d3c849d4b6af1a3542665b21732e2f5114631163d789cde7c92
3
+ metadata.gz: 8e6b9ef04034e352b060629804f97e6839549956af1f8e25d974fc753ea641c7
4
+ data.tar.gz: fe56159e4101d1c66346cac2cdf3dfbb2e6ed4080e1605aa637e92935ce1966a
5
5
  SHA512:
6
- metadata.gz: eb15c44e7a4372de8f9aed4ec69f4070bffdd9311e32606b91d81b3326ff343e5d64d5346f3a604be0f83ce623ba13d45ea63ace209ba9bc47f758dcc7d8e05f
7
- data.tar.gz: a9c67ce3cdc6faf65fc8467d043bf9907d58933bdff9131b184ee29d735277a88d597846c04bcbe1ae3e2990aca62c8b19e6b90307c16bdd69b7b2b863166b29
6
+ metadata.gz: 6b638389652e92e58fe69763ae69e83b8634ca0900ef356e736decc7058fff37fd138ebbb29713ed62cd6947cb211da24fb0cef5446e9701cb271d84e0d3450b
7
+ data.tar.gz: f16fdece02dab5e1c92fd0205d0cb86d882afcb91dac56ff6a559278a2219f9fde9a2442779ff088a98e85f058f99c5eef08710dbcd4ddeb3a18a956c77cb49e
data/CHANGES.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### 2025-11-07 (2.16.0)
6
+
7
+ * Deprecate `JSON::State#[]` and `JSON::State#[]=`. Consider using `JSON::Coder` instead.
8
+ * `JSON::Coder` now also yields to the block when encountering strings with invalid encoding.
9
+ * Fix GeneratorError messages to be UTF-8 encoded.
10
+ * Fix memory leak when `Exception` is raised, or `throw` is used during JSON generation.
11
+ * Optimized floating point number parsing by integrating the ryu algorithm (thanks to Josef Šimánek).
12
+ * Optimized numbers parsing using SWAR (thanks to Scott Myron).
13
+ * Optimized parsing of pretty printed documents using SWAR (thanks to Scott Myron).
14
+
15
+ ### 2025-10-25 (2.15.2)
16
+
17
+ * Fix `JSON::Coder` to have one dedicated depth counter per invocation.
18
+ After encountering a circular reference in `JSON::Coder#dump`, any further `#dump` call would raise `JSON::NestingError`.
19
+
5
20
  ### 2025-10-07 (2.15.1)
6
21
 
7
22
  * Fix incorrect escaping in the JRuby extension when encoding shared strings.
data/LEGAL CHANGED
@@ -6,3 +6,15 @@
6
6
  All the files in this distribution are covered under either the Ruby's
7
7
  license (see the file COPYING) or public-domain except some files
8
8
  mentioned below.
9
+
10
+ ext/json/ext/vendor/fpconv.h::
11
+ This file is adapted from https://github.com/night-shift/fpconv
12
+ It is licensed under Boost Software License 1.0.
13
+
14
+ ext/json/ext/vendor/jeaiii-ltoa.h::
15
+ This file is adapted from https://github.com/jeaiii/itoa
16
+ It is licensed under the MIT License
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.
data/README.md CHANGED
@@ -113,7 +113,23 @@ puts MyApp::API_JSON_CODER.dump(Time.now.utc) # => "2025-01-21T08:41:44.286Z"
113
113
  The provided block is called for all objects that don't have a native JSON equivalent, and
114
114
  must return a Ruby object that has a native JSON equivalent.
115
115
 
116
- It is also called for objects that do have a JSON equivalent, but are used as Hash keys, for instance `{ 1 => 2}`.
116
+ It is also called for objects that do have a JSON equivalent, but are used as Hash keys, for instance `{ 1 => 2}`,
117
+ as well as for strings that aren't valid UTF-8:
118
+
119
+ ```ruby
120
+ coder = JSON::Combining.new do |object, is_object_key|
121
+ case object
122
+ when String
123
+ if !string.valid_encoding? || string.encoding != Encoding::UTF_8
124
+ Base64.encode64(string)
125
+ else
126
+ string
127
+ end
128
+ else
129
+ object
130
+ end
131
+ end
132
+ ```
117
133
 
118
134
  ## Combining JSON fragments
119
135
 
data/lib/json/common.rb CHANGED
@@ -71,8 +71,13 @@ module JSON
71
71
  end
72
72
  when object_class
73
73
  if opts[:create_additions] != false
74
- if class_name = object[JSON.create_id]
75
- klass = JSON.deep_const_get(class_name)
74
+ if class_path = object[JSON.create_id]
75
+ klass = begin
76
+ Object.const_get(class_path)
77
+ rescue NameError => e
78
+ raise ArgumentError, "can't get const #{class_path}: #{e}"
79
+ end
80
+
76
81
  if klass.respond_to?(:json_creatable?) ? klass.json_creatable? : klass.respond_to?(:json_create)
77
82
  create_additions_warning if create_additions.nil?
78
83
  object = klass.json_create(object)
@@ -147,16 +152,6 @@ module JSON
147
152
  const_set :Parser, parser
148
153
  end
149
154
 
150
- # Return the constant located at _path_. The format of _path_ has to be
151
- # either ::A::B::C or A::B::C. In any case, A has to be located at the top
152
- # level (absolute namespace path?). If there doesn't exist a constant at
153
- # the given path, an ArgumentError is raised.
154
- def deep_const_get(path) # :nodoc:
155
- Object.const_get(path)
156
- rescue NameError => e
157
- raise ArgumentError, "can't get const #{path}: #{e}"
158
- end
159
-
160
155
  # Set the module _generator_ to be used by JSON.
161
156
  def generator=(generator) # :nodoc:
162
157
  old, $VERBOSE = $VERBOSE, nil
@@ -75,6 +75,8 @@ module JSON
75
75
  #
76
76
  # Returns the value returned by method +name+.
77
77
  def [](name)
78
+ ::JSON.deprecation_warning("JSON::State#[] is deprecated and will be removed in json 3.0.0")
79
+
78
80
  if respond_to?(name)
79
81
  __send__(name)
80
82
  else
@@ -87,6 +89,8 @@ module JSON
87
89
  #
88
90
  # Sets the attribute name to value.
89
91
  def []=(name, value)
92
+ ::JSON.deprecation_warning("JSON::State#[]= is deprecated and will be removed in json 3.0.0")
93
+
90
94
  if respond_to?(name_writer = "#{name}=")
91
95
  __send__ name_writer, value
92
96
  else
Binary file
Binary file
@@ -55,6 +55,11 @@ module JSON
55
55
  (Symbol === key || String === key)
56
56
  end
57
57
 
58
+ def self.valid_encoding?(string) # :nodoc:
59
+ return false unless string.encoding == ::Encoding::UTF_8 || string.encoding == ::Encoding::US_ASCII
60
+ string.is_a?(Symbol) || string.valid_encoding?
61
+ end
62
+
58
63
  # Convert a UTF8 encoded Ruby string _string_ to a JSON string, encoded with
59
64
  # UTF16 big endian characters as \u????, and return it.
60
65
  def self.utf8_to_json(string, script_safe = false) # :nodoc:
@@ -212,7 +217,7 @@ module JSON
212
217
  return if @max_nesting.zero?
213
218
  current_nesting = depth + 1
214
219
  current_nesting > @max_nesting and
215
- raise NestingError, "nesting of #{current_nesting} is too deep"
220
+ raise NestingError, "nesting of #{current_nesting} is too deep. Did you try to serialize objects with circular references?"
216
221
  end
217
222
 
218
223
  # Returns true, if circular data structures are checked,
@@ -347,6 +352,10 @@ module JSON
347
352
  dup.generate(obj, anIO)
348
353
  end
349
354
 
355
+ private def initialize_copy(_orig)
356
+ @depth = 0
357
+ end
358
+
350
359
  # Handles @allow_nan, @buffer_initial_length, other ivars must be the default value (see above)
351
360
  private def generate_json(obj, buf)
352
361
  case obj
@@ -430,6 +439,8 @@ module JSON
430
439
 
431
440
  # Return the value returned by method +name+.
432
441
  def [](name)
442
+ ::JSON.deprecation_warning("JSON::State#[] is deprecated and will be removed in json 3.0.0")
443
+
433
444
  if respond_to?(name)
434
445
  __send__(name)
435
446
  else
@@ -439,6 +450,8 @@ module JSON
439
450
  end
440
451
 
441
452
  def []=(name, value)
453
+ ::JSON.deprecation_warning("JSON::State#[]= is deprecated and will be removed in json 3.0.0")
454
+
442
455
  if respond_to?(name_writer = "#{name}=")
443
456
  __send__ name_writer, value
444
457
  else
@@ -517,13 +530,17 @@ module JSON
517
530
  end
518
531
  result << state.indent * depth if indent
519
532
 
520
- if state.strict? && !Generator.native_key?(key)
521
- if state.as_json
533
+ if state.strict?
534
+ if state.as_json && (!Generator.native_key?(key) || !Generator.valid_encoding?(key))
522
535
  key = state.as_json.call(key, true)
523
536
  end
524
537
 
525
538
  unless Generator.native_key?(key)
526
- raise GeneratorError.new("#{key.class} not allowed as object key in JSON", value)
539
+ raise GeneratorError.new("#{key.class} not allowed as object key in JSON", key)
540
+ end
541
+
542
+ unless Generator.valid_encoding?(key)
543
+ raise GeneratorError.new("source sequence is illegal/malformed utf-8", key)
527
544
  end
528
545
  end
529
546
 
@@ -670,14 +687,25 @@ module JSON
670
687
  # \u????.
671
688
  def to_json(state = nil, *args)
672
689
  state = State.from_state(state)
673
- if encoding == ::Encoding::UTF_8
674
- unless valid_encoding?
690
+ string = self
691
+
692
+ if state.strict? && state.as_json
693
+ unless Generator.valid_encoding?(string)
694
+ string = state.as_json.call(string, false)
695
+ unless string.is_a?(::String)
696
+ return string.to_json(state, *args)
697
+ end
698
+ end
699
+ end
700
+
701
+ if string.encoding == ::Encoding::UTF_8
702
+ unless string.valid_encoding?
675
703
  raise GeneratorError.new("source sequence is illegal/malformed utf-8", self)
676
704
  end
677
- string = self
678
705
  else
679
- string = encode(::Encoding::UTF_8)
706
+ string = string.encode(::Encoding::UTF_8)
680
707
  end
708
+
681
709
  if state.ascii_only?
682
710
  %("#{JSON::TruffleRuby::Generator.utf8_to_json_ascii(string, state.script_safe)}")
683
711
  else
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.15.1'
4
+ VERSION = '2.16.0'
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.15.1
4
+ version: 2.16.0
5
5
  platform: java
6
6
  authors:
7
7
  - Daniel Luz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-07 00:00:00.000000000 Z
11
+ date: 2025-11-07 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