json 2.18.1-java → 2.19.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: 6910de3b175b876dd2565856cdd7df4b04cc96fdb9076709287644b8a3a9748a
4
- data.tar.gz: 1da208a71639069ec574857a6e134964becd6d580b1196b5403d086372174cef
3
+ metadata.gz: c4a3d5e247eea23a566aabe1c6a2e9334a9a46ec69ba90639d2513f9269ffc9e
4
+ data.tar.gz: 5a679f916d35f16478e754fcbceb660c53bcf6c37148e610d6cfa5ce75bdc8b8
5
5
  SHA512:
6
- metadata.gz: 10e4ac9a7c71c9fd5576f8971d682b1cb4dda0a5c76ff176907b6be03c4f935b89c098c74cdd6095950377839128dda774835641b8d688bff03df1be46f46f87
7
- data.tar.gz: 5852bba834c3f679f93076f02ade8860e5105f32a4093f3471e807de4fbb97980213feba5f6471a5803bd9400b06aa1d06e0dee5e893e098c474153a0b8cd70c
6
+ metadata.gz: dfca69074ee5a8854422756958e850fc6d749464b89f79e4f24a6c5dbc83424e7fb939ba6770b00de529c64bf5d82447adbefa11f805a076fe7e8e8d7aa07be0
7
+ data.tar.gz: 79a3be36a9121be61a608ca4a418ab62ce7732cb5edb1ff76c88c4d2a63b703481baf30fcc94c6b921476d3eb92223dae5e5d72b47af8c14647073ba163197b9
data/CHANGES.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### 2026-03-06 (2.19.0)
6
+
7
+ * Fix `allow_blank` parsing option to no longer allow invalid types (e.g. `load([], allow_blank: true)` now raise a type error).
8
+ * Add `allow_invalid_escape` parsing option to ignore backslashes that aren't followed by one of the valid escape characters.
9
+
5
10
  ### 2026-02-03 (2.18.1)
6
11
 
7
12
  * Fix a potential crash in very specific circumstance if GC triggers during a call to `to_json`
data/lib/json/common.rb CHANGED
@@ -156,15 +156,17 @@ module JSON
156
156
  def generator=(generator) # :nodoc:
157
157
  old, $VERBOSE = $VERBOSE, nil
158
158
  @generator = generator
159
- generator_methods = generator::GeneratorMethods
160
- for const in generator_methods.constants
161
- klass = const_get(const)
162
- modul = generator_methods.const_get(const)
163
- klass.class_eval do
164
- instance_methods(false).each do |m|
165
- m.to_s == 'to_json' and remove_method m
159
+ if generator.const_defined?(:GeneratorMethods)
160
+ generator_methods = generator::GeneratorMethods
161
+ for const in generator_methods.constants
162
+ klass = const_get(const)
163
+ modul = generator_methods.const_get(const)
164
+ klass.class_eval do
165
+ instance_methods(false).each do |m|
166
+ m.to_s == 'to_json' and remove_method m
167
+ end
168
+ include modul
166
169
  end
167
- include modul
168
170
  end
169
171
  end
170
172
  self.state = generator::State
@@ -878,7 +880,7 @@ module JSON
878
880
  end
879
881
  end
880
882
 
881
- if opts[:allow_blank] && (source.nil? || source.empty?)
883
+ if opts[:allow_blank] && (source.nil? || (String === source && source.empty?))
882
884
  source = 'null'
883
885
  end
884
886
 
@@ -1036,7 +1038,8 @@ module JSON
1036
1038
  # JSON.new(options = nil, &block)
1037
1039
  #
1038
1040
  # Argument +options+, if given, contains a \Hash of options for both parsing and generating.
1039
- # See {Parsing Options}[#module-JSON-label-Parsing+Options], and {Generating Options}[#module-JSON-label-Generating+Options].
1041
+ # See {Parsing Options}[rdoc-ref:JSON@Parsing+Options],
1042
+ # and {Generating Options}[rdoc-ref:JSON@Generating+Options].
1040
1043
  #
1041
1044
  # For generation, the <tt>strict: true</tt> option is always set. When a Ruby object with no native \JSON counterpart is
1042
1045
  # encountered, the block provided to the initialize method is invoked, and must return a Ruby object that has a native
@@ -1095,6 +1098,30 @@ module JSON
1095
1098
  load(File.read(path, encoding: Encoding::UTF_8))
1096
1099
  end
1097
1100
  end
1101
+
1102
+ module GeneratorMethods
1103
+ # call-seq: to_json(*)
1104
+ #
1105
+ # Converts this object into a JSON string.
1106
+ # If this object doesn't directly maps to a JSON native type,
1107
+ # first convert it to a string (calling #to_s), then converts
1108
+ # it to a JSON string, and returns the result.
1109
+ # This is a fallback, if no special method #to_json was defined for some object.
1110
+ def to_json(state = nil, *)
1111
+ obj = case self
1112
+ when nil, false, true, Integer, Float, Array, Hash
1113
+ self
1114
+ else
1115
+ "#{self}"
1116
+ end
1117
+
1118
+ if state.nil?
1119
+ JSON::State._generate_no_fallback(obj, nil, nil)
1120
+ else
1121
+ JSON::State.from_state(state)._generate_no_fallback(obj)
1122
+ end
1123
+ end
1124
+ end
1098
1125
  end
1099
1126
 
1100
1127
  module ::Kernel
@@ -1140,3 +1167,7 @@ module ::Kernel
1140
1167
  JSON[object, opts]
1141
1168
  end
1142
1169
  end
1170
+
1171
+ class Object
1172
+ include JSON::GeneratorMethods
1173
+ end
@@ -9,7 +9,7 @@ module JSON
9
9
  # Instantiates a new State object, configured by _opts_.
10
10
  #
11
11
  # Argument +opts+, if given, contains a \Hash of options for the generation.
12
- # See {Generating Options}[#module-JSON-label-Generating+Options].
12
+ # See {Generating Options}[rdoc-ref:JSON@Generating+Options].
13
13
  def initialize(opts = nil)
14
14
  if opts && !opts.empty?
15
15
  configure(opts)
Binary file
Binary file
@@ -211,7 +211,14 @@ module JSON
211
211
 
212
212
  # This integer returns the current depth data structure nesting in the
213
213
  # generated JSON.
214
- attr_accessor :depth
214
+ attr_reader :depth
215
+
216
+ def depth=(depth)
217
+ if depth.negative?
218
+ raise ArgumentError, "depth must be >= 0 (got #{depth})"
219
+ end
220
+ @depth = depth
221
+ end
215
222
 
216
223
  def check_max_nesting # :nodoc:
217
224
  return if @max_nesting.zero?
@@ -260,6 +267,11 @@ module JSON
260
267
  else
261
268
  raise TypeError, "can't convert #{opts.class} into Hash"
262
269
  end
270
+
271
+ if opts[:depth]&.negative?
272
+ raise ArgumentError, "depth must be >= 0 (got #{opts[:depth]})"
273
+ end
274
+
263
275
  opts.each do |key, value|
264
276
  instance_variable_set "@#{key}", value
265
277
  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 = '2.18.1'
4
+ VERSION = '2.19.0'
5
5
  end
data/lib/json.rb CHANGED
@@ -194,6 +194,18 @@ require 'json/common'
194
194
  # When enabled:
195
195
  # JSON.parse(%{"Hello\nWorld"}, allow_control_characters: true) # => "Hello\nWorld"
196
196
  #
197
+ # ---
198
+ #
199
+ # Option +allow_invalid_escape+ (boolean) specifies whether to ignore backslahes that are followed
200
+ # by an invalid escape character in strings;
201
+ # defaults to +false+.
202
+ #
203
+ # With the default, +false+:
204
+ # JSON.parse('"Hell\o"') # invalid escape character in string (JSON::ParserError)
205
+ #
206
+ # When enabled:
207
+ # JSON.parse('"Hell\o"', allow_invalid_escape: true) # => "Hello"
208
+ #
197
209
  # ====== Output Options
198
210
  #
199
211
  # Option +freeze+ (boolean) specifies whether the returned objects will be frozen;
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.18.1
4
+ version: 2.19.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: 2026-02-03 00:00:00.000000000 Z
11
+ date: 2026-03-06 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