json 2.15.2-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: 48d22171870875f79dc860de151f8ad1ca9b3658d70ba4b12b8eb303221108fa
4
- data.tar.gz: f2a4754a3852a4791e3a62fce1966f613fe0167f0cb8748491922e4ddeab170f
3
+ metadata.gz: 8e6b9ef04034e352b060629804f97e6839549956af1f8e25d974fc753ea641c7
4
+ data.tar.gz: fe56159e4101d1c66346cac2cdf3dfbb2e6ed4080e1605aa637e92935ce1966a
5
5
  SHA512:
6
- metadata.gz: efe4e79202ce017a55d516b2c7f473e63d58c536986130cf68c3f473c9ae8ca819e13d590b79f04b7e845c83425a29b22062bfdeaecd227577b9c56ed94f4e3b
7
- data.tar.gz: 96da2d6068270a844bd6015ac0e67196c19b6c208f49e7adb71ad610662cce066d5d0dc294582a01153853f2186a03e06d20abbd16d7b6faf83dab05c097d84b
6
+ metadata.gz: 6b638389652e92e58fe69763ae69e83b8634ca0900ef356e736decc7058fff37fd138ebbb29713ed62cd6947cb211da24fb0cef5446e9701cb271d84e0d3450b
7
+ data.tar.gz: f16fdece02dab5e1c92fd0205d0cb86d882afcb91dac56ff6a559278a2219f9fde9a2442779ff088a98e85f058f99c5eef08710dbcd4ddeb3a18a956c77cb49e
data/CHANGES.md CHANGED
@@ -2,6 +2,16 @@
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
+
5
15
  ### 2025-10-25 (2.15.2)
6
16
 
7
17
  * Fix `JSON::Coder` to have one dedicated depth counter per invocation.
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:
@@ -434,6 +439,8 @@ module JSON
434
439
 
435
440
  # Return the value returned by method +name+.
436
441
  def [](name)
442
+ ::JSON.deprecation_warning("JSON::State#[] is deprecated and will be removed in json 3.0.0")
443
+
437
444
  if respond_to?(name)
438
445
  __send__(name)
439
446
  else
@@ -443,6 +450,8 @@ module JSON
443
450
  end
444
451
 
445
452
  def []=(name, value)
453
+ ::JSON.deprecation_warning("JSON::State#[]= is deprecated and will be removed in json 3.0.0")
454
+
446
455
  if respond_to?(name_writer = "#{name}=")
447
456
  __send__ name_writer, value
448
457
  else
@@ -521,13 +530,17 @@ module JSON
521
530
  end
522
531
  result << state.indent * depth if indent
523
532
 
524
- if state.strict? && !Generator.native_key?(key)
525
- if state.as_json
533
+ if state.strict?
534
+ if state.as_json && (!Generator.native_key?(key) || !Generator.valid_encoding?(key))
526
535
  key = state.as_json.call(key, true)
527
536
  end
528
537
 
529
538
  unless Generator.native_key?(key)
530
- 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)
531
544
  end
532
545
  end
533
546
 
@@ -674,14 +687,25 @@ module JSON
674
687
  # \u????.
675
688
  def to_json(state = nil, *args)
676
689
  state = State.from_state(state)
677
- if encoding == ::Encoding::UTF_8
678
- 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?
679
703
  raise GeneratorError.new("source sequence is illegal/malformed utf-8", self)
680
704
  end
681
- string = self
682
705
  else
683
- string = encode(::Encoding::UTF_8)
706
+ string = string.encode(::Encoding::UTF_8)
684
707
  end
708
+
685
709
  if state.ascii_only?
686
710
  %("#{JSON::TruffleRuby::Generator.utf8_to_json_ascii(string, state.script_safe)}")
687
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.2'
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.2
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-25 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