json 2.16.0-java → 2.17.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: 8e6b9ef04034e352b060629804f97e6839549956af1f8e25d974fc753ea641c7
4
- data.tar.gz: fe56159e4101d1c66346cac2cdf3dfbb2e6ed4080e1605aa637e92935ce1966a
3
+ metadata.gz: d56d853c903b3ec52d57a6bfdf5561e8d2201b9154c6bc01b9b6d19975c89fa1
4
+ data.tar.gz: a881ffcd7f7ce84310437d8d962a306ac211027bd445aa00447a0d431c8c63d3
5
5
  SHA512:
6
- metadata.gz: 6b638389652e92e58fe69763ae69e83b8634ca0900ef356e736decc7058fff37fd138ebbb29713ed62cd6947cb211da24fb0cef5446e9701cb271d84e0d3450b
7
- data.tar.gz: f16fdece02dab5e1c92fd0205d0cb86d882afcb91dac56ff6a559278a2219f9fde9a2442779ff088a98e85f058f99c5eef08710dbcd4ddeb3a18a956c77cb49e
6
+ metadata.gz: 63541eade76e9363ed4e5b995a3828ad2b7b0d2f8ef5a7e9a9682496a2e864af05870258b08eda59218a9a928747e274ec93d653b6e4f34c1009fc581bd584e4
7
+ data.tar.gz: ac8045765538bbd965aacfba95cd282331f0b1c874a9fc96475841c336e6b3a2ad183d940b32e7821dbb0cbee960c5b691ac14a3dba1c7eef2ca9295aedc727a
data/CHANGES.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### 2025-12-03 (2.17.0)
6
+
7
+ * Improve `JSON.load` and `JSON.unsafe_load` to allow passing options as second argument.
8
+ * Fix the parser to no longer ignore invalid escapes in strings.
9
+ Only `\"`, `\\`, `\b`, `\f`, `\n`, `\r`, `\t` and `\u` are valid JSON escapes.
10
+ * Fixed `JSON::Coder` to use the depth it was initialized with.
11
+ * On TruffleRuby, fix the generator to not call `to_json` on the return value of `as_json` for `Float::NAN`.
12
+ * Fixed handling of `state.depth`: when `to_json` changes `state.depth` but does not restore it, it is reset
13
+ automatically to its initial value.
14
+ In particular, when a `NestingError` is raised, `depth` is no longer equal to `max_nesting` after the call to
15
+ generate, and is reset to its initial value. Similarly when `to_json` raises an exception.
16
+
5
17
  ### 2025-11-07 (2.16.0)
6
18
 
7
19
  * Deprecate `JSON::State#[]` and `JSON::State#[]=`. Consider using `JSON::Coder` instead.
data/lib/json/common.rb CHANGED
@@ -550,6 +550,7 @@ module JSON
550
550
  :create_additions => nil,
551
551
  }
552
552
  # :call-seq:
553
+ # JSON.unsafe_load(source, options = {}) -> object
553
554
  # JSON.unsafe_load(source, proc = nil, options = {}) -> object
554
555
  #
555
556
  # Returns the Ruby objects created by parsing the given +source+.
@@ -681,7 +682,12 @@ module JSON
681
682
  #
682
683
  def unsafe_load(source, proc = nil, options = nil)
683
684
  opts = if options.nil?
684
- _unsafe_load_default_options
685
+ if proc && proc.is_a?(Hash)
686
+ options, proc = proc, nil
687
+ options
688
+ else
689
+ _unsafe_load_default_options
690
+ end
685
691
  else
686
692
  _unsafe_load_default_options.merge(options)
687
693
  end
@@ -709,6 +715,7 @@ module JSON
709
715
  end
710
716
 
711
717
  # :call-seq:
718
+ # JSON.load(source, options = {}) -> object
712
719
  # JSON.load(source, proc = nil, options = {}) -> object
713
720
  #
714
721
  # Returns the Ruby objects created by parsing the given +source+.
@@ -845,8 +852,18 @@ module JSON
845
852
  # @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
846
853
  #
847
854
  def load(source, proc = nil, options = nil)
855
+ if proc && options.nil? && proc.is_a?(Hash)
856
+ options = proc
857
+ proc = nil
858
+ end
859
+
848
860
  opts = if options.nil?
849
- _load_default_options
861
+ if proc && proc.is_a?(Hash)
862
+ options, proc = proc, nil
863
+ options
864
+ else
865
+ _load_default_options
866
+ end
850
867
  else
851
868
  _load_default_options.merge(options)
852
869
  end
@@ -1048,7 +1065,7 @@ module JSON
1048
1065
  options[:as_json] = as_json if as_json
1049
1066
 
1050
1067
  @state = State.new(options).freeze
1051
- @parser_config = Ext::Parser::Config.new(ParserOptions.prepare(options))
1068
+ @parser_config = Ext::Parser::Config.new(ParserOptions.prepare(options)).freeze
1052
1069
  end
1053
1070
 
1054
1071
  # call-seq:
@@ -1057,7 +1074,7 @@ module JSON
1057
1074
  #
1058
1075
  # Serialize the given object into a \JSON document.
1059
1076
  def dump(object, io = nil)
1060
- @state.generate_new(object, io)
1077
+ @state.generate(object, io)
1061
1078
  end
1062
1079
  alias_method :generate, :dump
1063
1080
 
Binary file
Binary file
@@ -312,8 +312,8 @@ module JSON
312
312
  def to_h
313
313
  result = {}
314
314
  instance_variables.each do |iv|
315
- iv = iv.to_s[1..-1]
316
- result[iv.to_sym] = self[iv]
315
+ key = iv.to_s[1..-1]
316
+ result[key.to_sym] = instance_variable_get(iv)
317
317
  end
318
318
 
319
319
  if result[:allow_duplicate_key].nil?
@@ -330,6 +330,9 @@ module JSON
330
330
  # created this method raises a
331
331
  # GeneratorError exception.
332
332
  def generate(obj, anIO = nil)
333
+ return dup.generate(obj, anIO) if frozen?
334
+
335
+ depth = @depth
333
336
  if @indent.empty? and @space.empty? and @space_before.empty? and @object_nl.empty? and @array_nl.empty? and
334
337
  !@ascii_only and !@script_safe and @max_nesting == 0 and (!@strict || Symbol === obj)
335
338
  result = generate_json(obj, ''.dup)
@@ -346,14 +349,8 @@ module JSON
346
349
  else
347
350
  result
348
351
  end
349
- end
350
-
351
- def generate_new(obj, anIO = nil) # :nodoc:
352
- dup.generate(obj, anIO)
353
- end
354
-
355
- private def initialize_copy(_orig)
356
- @depth = 0
352
+ ensure
353
+ @depth = depth unless frozen?
357
354
  end
358
355
 
359
356
  # Handles @allow_nan, @buffer_initial_length, other ivars must be the default value (see above)
@@ -494,8 +491,11 @@ module JSON
494
491
  # _depth_ is used to find out nesting depth, to indent accordingly.
495
492
  def to_json(state = nil, *)
496
493
  state = State.from_state(state)
494
+ depth = state.depth
497
495
  state.check_max_nesting
498
496
  json_transform(state)
497
+ ensure
498
+ state.depth = depth
499
499
  end
500
500
 
501
501
  private
@@ -559,17 +559,19 @@ module JSON
559
559
  raise GeneratorError.new("#{value.class} returned by #{state.as_json} not allowed in JSON", value)
560
560
  end
561
561
  result << value.to_json(state)
562
+ state.depth = depth
562
563
  else
563
564
  raise GeneratorError.new("#{value.class} not allowed in JSON", value)
564
565
  end
565
566
  elsif value.respond_to?(:to_json)
566
567
  result << value.to_json(state)
568
+ state.depth = depth
567
569
  else
568
570
  result << %{"#{String(value)}"}
569
571
  end
570
572
  first = false
571
573
  }
572
- depth = state.depth -= 1
574
+ depth -= 1
573
575
  unless first
574
576
  result << state.object_nl
575
577
  result << state.indent * depth if indent
@@ -586,8 +588,11 @@ module JSON
586
588
  # produced JSON string output further.
587
589
  def to_json(state = nil, *)
588
590
  state = State.from_state(state)
591
+ depth = state.depth
589
592
  state.check_max_nesting
590
593
  json_transform(state)
594
+ ensure
595
+ state.depth = depth
591
596
  end
592
597
 
593
598
  private
@@ -625,12 +630,13 @@ module JSON
625
630
  end
626
631
  elsif value.respond_to?(:to_json)
627
632
  result << value.to_json(state)
633
+ state.depth = depth
628
634
  else
629
635
  result << %{"#{String(value)}"}
630
636
  end
631
637
  first = false
632
638
  }
633
- depth = state.depth -= 1
639
+ depth -= 1
634
640
  result << state.array_nl
635
641
  result << state.indent * depth if indent
636
642
  result << ']'
@@ -655,6 +661,9 @@ module JSON
655
661
  if casted_value.equal?(self)
656
662
  raise GeneratorError.new("#{self} not allowed in JSON", self)
657
663
  end
664
+ unless Generator.native_type?(casted_value)
665
+ raise GeneratorError.new("#{casted_value.class} returned by #{state.as_json} not allowed in JSON", casted_value)
666
+ end
658
667
 
659
668
  state.check_max_nesting
660
669
  state.depth += 1
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.16.0'
4
+ VERSION = '2.17.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.16.0
4
+ version: 2.17.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-11-07 00:00:00.000000000 Z
11
+ date: 2025-12-03 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