json 3.1.0-java → 3.2.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: ee1372af8bb19939f969cebf3d301b38b9d03c40e48ed62d9d0eda90eb04692f
4
- data.tar.gz: b380bcb62bfd92420834b2ce75f6fc1e298be512a15f4a5ac5839e967b51c23f
3
+ metadata.gz: 137f00c15cef4a2c357c2e477b3a0fa23bddcca952a65c167c9d50e4aa7e54fa
4
+ data.tar.gz: 271b7709a5ed95e2a7a7317ba4d83ea326af3298987ecf75d953d51395f422a8
5
5
  SHA512:
6
- metadata.gz: e9788ac086e362d08433e0027ffc269ec4dd58075165b86b0a4fa4c2da7d9de8583d155bf79b0b4389eaab3b10ff92e3b162b808e3dd413b22b2e3473e67fdd4
7
- data.tar.gz: 51800b6ce2d20e0916b1244f9d18ab10ba3727e0bb03634f723774280fab00f731b0860dd97952e4cdc81ab02fe613260a29afa6547ff2640434df116fe7f9cd
6
+ metadata.gz: 316d292bcb74ff5d867366743f4e7ee919f3b79baaf51ef1034f92a75dd2a481cc063e04b95e7c382e00324b3efae13ab4a53b37a78e5997d0d4a96f97a44b28
7
+ data.tar.gz: fcc784f5e92bca1b216bb3bfe2a20cc04ab8546d62d57b1717bfd87c6d1e5ecc2bb2576833c01b9c79ecf6c8a5359fd853446e570945b8eb52c273809e0b30e1
data/CHANGES.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### 2026-11-24 (3.2.0)
6
+
7
+ * The `script_safe: true` option of `JSON.generate` no longer escapes forward slashes `/`, and instead escapes script tag
8
+ openings (`<script`), script tag closing (`</script`) and HTML comments (`<!--`) as recommended by the HTML spec.
9
+ * The `script_safe: true` option of `JSON.generate` no longer escapes `U+2028` and `U+2029` given that Javascript is
10
+ now a proper subset of JSON since many years (see: https://github.com/tc39/proposal-json-superset).
11
+ * Fix `JSON::ParserError#json_path` raising `NoMethodError` when the document was parsed with `symbolize_names: true`.
12
+ * Fix `JSON.generate` not detecting duplicate keys such as `{ "1" => 1, 1 => 2 }`.
13
+ * JRuby: raise `TypeError` when a String subclass used as a Hash key has a `to_s` that doesn't return a String, like the C extension.
14
+ * JRuby and TruffleRuby: fix a stack overflow in `JSON::Coder` when `as_json` returns a Symbol for a string with invalid encoding.
15
+ * JRuby: fix `JSON::Coder` (and any frozen `JSON::State`) not being thread-safe. Each `#dump` call now uses its own nesting depth instead of mutating the shared state, which under concurrent use could make every later call raise `JSON::NestingError`.
16
+
5
17
  ### 2026-10-13 (3.1.0)
6
18
 
7
19
  * Added `rfc8785` generator option to canonicalize the output. Replaces the `json-canonicalization` with numerous correctness fixes.
@@ -138,6 +150,15 @@ Numerous rarely used aliases have been removed.
138
150
  * Fix `allow_blank` parsing option to no longer allow invalid types (e.g. `load([], allow_blank: true)` now raise a type error).
139
151
  * Add `allow_invalid_escape` parsing option to ignore backslashes that aren't followed by one of the valid escape characters.
140
152
 
153
+ ### 2026-11-13 (2.18.3)
154
+
155
+ * Backport format string injection fix from 2.19.2. `CVE-2026-33210` / GHSA-3m6g-2423-7cp3.
156
+
157
+ ### 2026-11-02 (2.18.2)
158
+
159
+ * Backport handling of unescaped control characters preceeded by a backslash from 2.19.3.
160
+ GHSA-cjpr-jw2g-fw99.
161
+
141
162
  ### 2026-02-03 (2.18.1)
142
163
 
143
164
  * Fix a potential crash in very specific circumstance if GC triggers during a call to `to_json`
data/lib/json/common.rb CHANGED
@@ -171,13 +171,14 @@ module JSON
171
171
  when Integer
172
172
  "[#{segment}]"
173
173
  when String, Symbol
174
+ segment = segment.to_s
174
175
  if !segment.valid_encoding?
175
176
  segment = segment.b.gsub(/["\\]/n, { '"' => '\\"', '\\' => '\\\\' }).force_encoding(Encoding::UTF_8)
176
177
  %{["#{segment}"]}
177
178
  elsif segment.match?(/\A[a-zA-Z\$\_][a-zA-Z\$\_0-9]*\z/)
178
179
  ".#{segment}"
179
180
  else
180
- segment = segment.to_s.gsub(/["\\]/, { '"' => '\\"', '\\' => '\\\\' })
181
+ segment = segment.gsub(/["\\]/, { '"' => '\\"', '\\' => '\\\\' })
181
182
  %{["#{segment}"]}
182
183
  end
183
184
  else
Binary file
Binary file
@@ -37,15 +37,12 @@ module JSON
37
37
  "\x1f" => '\u001f',
38
38
  '"' => '\"',
39
39
  '\\' => '\\\\',
40
+ '<' => '\\u003c',
40
41
  }.freeze # :nodoc:
41
42
 
42
- SCRIPT_SAFE_MAP = MAP.merge(
43
- '/' => '\\/',
44
- "\u2028" => '\u2028',
45
- "\u2029" => '\u2029',
46
- ).freeze
43
+ ESCAPE_PATTERN = /["\\\x0-\x1f]/
47
44
 
48
- SCRIPT_SAFE_ESCAPE_PATTERN = /[\/"\\\x0-\x1f\u2028-\u2029]/
45
+ SCRIPT_SAFE_ESCAPE_PATTERN = Regexp.union(ESCAPE_PATTERN, /<(?=\/?script)/i, /<(?=!--)/)
49
46
 
50
47
  def self.native_type?(value) # :nodoc:
51
48
  (false == value || true == value || nil == value || String === value || Symbol === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value)
@@ -63,25 +60,16 @@ module JSON
63
60
  # Convert a UTF8 encoded Ruby string _string_ to a JSON string, encoded with
64
61
  # UTF16 big endian characters as \u????, and return it.
65
62
  def self.utf8_to_json(string, script_safe = false) # :nodoc:
66
- if script_safe
67
- if SCRIPT_SAFE_ESCAPE_PATTERN.match?(string)
68
- string.gsub(SCRIPT_SAFE_ESCAPE_PATTERN, SCRIPT_SAFE_MAP)
69
- else
70
- string
71
- end
63
+ pattern = script_safe ? SCRIPT_SAFE_ESCAPE_PATTERN : ESCAPE_PATTERN
64
+ if pattern.match?(string)
65
+ string.gsub(pattern, MAP)
72
66
  else
73
- if /["\\\x0-\x1f]/.match?(string)
74
- string.gsub(/["\\\x0-\x1f]/, MAP)
75
- else
76
- string
77
- end
67
+ string
78
68
  end
79
69
  end
80
70
 
81
71
  def self.utf8_to_json_ascii(original_string, script_safe = false) # :nodoc:
82
- string = original_string.b
83
- map = script_safe ? SCRIPT_SAFE_MAP : MAP
84
- string.gsub!(/[\/"\\\x0-\x1f]/n) { map[$&] || $& }
72
+ string = utf8_to_json(original_string, script_safe).b
85
73
  string.gsub!(/(
86
74
  (?:
87
75
  [\xc2-\xdf][\x80-\xbf] |
@@ -146,7 +134,7 @@ module JSON
146
134
  # * *space_before*: a string that is put before a : pair delimiter (default: ''),
147
135
  # * *object_nl*: a string that is put at the end of a JSON object (default: ''),
148
136
  # * *array_nl*: a string that is put at the end of a JSON array (default: ''),
149
- # * *script_safe*: true if U+2028, U+2029 and forward slash (/) should be escaped
137
+ # * *script_safe*: true if forward slash (/) should be escaped
150
138
  # as to make the JSON object safe to interpolate in a script tag (default: false).
151
139
  # * *check_circular*: is deprecated now, use the :max_nesting option instead,
152
140
  # * *max_nesting*: sets the maximum level of data structure nesting in
@@ -207,7 +195,7 @@ module JSON
207
195
  # the generated JSON, max_nesting = 0 if no maximum is checked.
208
196
  attr_accessor :max_nesting
209
197
 
210
- # If this attribute is set to true, forward slashes will be escaped in
198
+ # If this attribute is set to true, script tags and HTML comments will be escaped in
211
199
  # all json strings.
212
200
  attr_accessor :script_safe
213
201
 
@@ -451,7 +439,11 @@ module JSON
451
439
  end
452
440
  obj.each_pair do |k,v|
453
441
  if first
454
- key_type = k.class
442
+ if ::String == k.class || ::Symbol == k.class
443
+ key_type = k.class
444
+ else
445
+ JSON.send(:on_mixed_keys_hash, obj)
446
+ end
455
447
  else
456
448
  if key_type && !@allow_duplicate_key && key_type != k.class
457
449
  key_type = nil # stop checking
@@ -592,7 +584,11 @@ module JSON
592
584
 
593
585
  hash.each { |key, value|
594
586
  if first
595
- key_type = key.class
587
+ if ::String == key.class || ::Symbol == key.class
588
+ key_type = key.class
589
+ else
590
+ JSON.send(:on_mixed_keys_hash, hash)
591
+ end
596
592
  else
597
593
  if key_type && !state.allow_duplicate_key? && key_type != key.class
598
594
  key_type = nil # stop checking
@@ -783,9 +779,18 @@ module JSON
783
779
 
784
780
  if state.strict? && state.as_json
785
781
  unless Generator.valid_encoding?(string)
786
- string = state.as_json.call(string, false)
787
- unless string.is_a?(::String)
788
- return string.to_json(state, *args)
782
+ coerced = state.as_json.call(string, false)
783
+ unless coerced.equal?(string)
784
+ # as_json is only called once, so a new string that is still
785
+ # invalid raises instead of calling it again.
786
+ coerced = coerced.name if coerced.is_a?(::Symbol)
787
+ unless coerced.is_a?(::String)
788
+ return coerced.to_json(state, *args)
789
+ end
790
+ unless Generator.valid_encoding?(coerced)
791
+ raise GeneratorError.new("source sequence is illegal/malformed utf-8", self)
792
+ end
793
+ string = coerced
789
794
  end
790
795
  end
791
796
  end
data/lib/json/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSON
4
- VERSION = '3.1.0'
4
+ VERSION = '3.2.0'
5
5
  end
data/lib/json.rb CHANGED
@@ -118,7 +118,7 @@ require 'json/common'
118
118
  #
119
119
  # ==== Parsing Options
120
120
  #
121
- # ====== Input Options
121
+ # ===== Input Options
122
122
  #
123
123
  # Option +max_nesting+ (\Integer) specifies the maximum nesting depth allowed;
124
124
  # defaults to +100+;
@@ -214,7 +214,7 @@ require 'json/common'
214
214
  # When enabled:
215
215
  # JSON.parse('"Hell\o"', allow_invalid_escape: true) # => "Hello"
216
216
  #
217
- # ====== Output Options
217
+ # ===== Output Options
218
218
  #
219
219
  # Option +freeze+ (boolean) specifies whether the returned objects will be frozen;
220
220
  # defaults to +false+.
@@ -323,7 +323,7 @@ require 'json/common'
323
323
  #
324
324
  # ==== Generating Options
325
325
  #
326
- # ====== Input Options
326
+ # ===== Input Options
327
327
  #
328
328
  # Option +allow_nan+ (boolean) specifies whether
329
329
  # +NaN+, +Infinity+, and +-Infinity+ may be generated;
@@ -378,7 +378,7 @@ require 'json/common'
378
378
  # which may leave the process in an unrecoverable state.
379
379
  # It is highly discouraged.
380
380
  #
381
- # ====== Escaping Options
381
+ # ===== Escaping Options
382
382
  #
383
383
  # Options +script_safe+ (boolean) specifies wether <tt>'\u2028'</tt>, <tt>'\u2029'</tt>
384
384
  # and <tt>'/'</tt> should be escaped as to make the JSON object safe to interpolate in script
@@ -387,7 +387,7 @@ require 'json/common'
387
387
  # Options +ascii_only+ (boolean) specifies wether all characters outside the ASCII range
388
388
  # should be escaped.
389
389
  #
390
- # ====== Output Options
390
+ # ===== Output Options
391
391
  #
392
392
  # The default formatting options generate the most compact
393
393
  # \JSON data, all on one line and with no whitespace.
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: 3.1.0
4
+ version: 3.2.0
5
5
  platform: java
6
6
  authors:
7
7
  - Daniel Luz
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-10-13 00:00:00.000000000 Z
10
+ date: 2026-11-24 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