json 2.19.4 → 2.19.5

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: 48a111e63867f6bb2c0cb1b2740a898f3102bc07ac196136e26ca9b68f510f89
4
- data.tar.gz: 2f760d8afae80555c483afaaa8bead26f045d26c394cc07843a85deaff7fdd40
3
+ metadata.gz: 0bbb85e1521c171ca73ab935cc00899ff3eb7086921a64542a3937fa9589848d
4
+ data.tar.gz: 328853f7f164d91522d6791a51cca5ccb3ae418410752a3fb72189bc14c157d5
5
5
  SHA512:
6
- metadata.gz: 6387b2c483c8f4d7ed304f33a3553a2fde78c04efeff7ae32a1e952380df92d6df87b543c22832907b007f758f09bd2f80ef4db0b5753e46fdf73f0e264e9e02
7
- data.tar.gz: c3c855b9e460768f83516914580c10854ea2b28ee73976e311ce55a0d2265576f65a23c41cccc47c7443d79883658962d1cf923880685d555b3af1ba0ebcb056
6
+ metadata.gz: 326b0621e562eebc66f155cee358ca295dde7584e7f60268a354da3e8a1a02e13bfcd9fef7f9b2f9f2ea196987b07bb9e50578347231f14d9fb0e863ac9445ac
7
+ data.tar.gz: 0e9e2ab4c91b5544ac8440613a0fd63aab2f7b7ce5a39f41e786af736e80ca28de8d3388057134dde05ba53f4f150d24aa1a8cde92dac82abbb4104740409631
data/CHANGES.md CHANGED
@@ -2,9 +2,13 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### 2026-05-04 (2.19.5)
6
+
7
+ * Cap the parser to emit a maximum of 5 deprecation warnings per document. Emitting more is not helpful.
8
+
5
9
  ### 2026-04-19 (2.19.4)
6
10
 
7
- * Fix parsing of out of range floats (very large exponents that lead ot either `0.0` or `Inf`).
11
+ * Fix parsing of out of range floats (very large exponents that lead to either `0.0` or `Inf`).
8
12
 
9
13
  ### 2026-03-25 (2.19.3)
10
14
 
@@ -819,9 +819,17 @@ static VALUE encode_json_string_rescue(VALUE str, VALUE exception)
819
819
  return Qundef;
820
820
  }
821
821
 
822
+ static inline int json_str_coderange(VALUE str) {
823
+ int coderange = RB_ENC_CODERANGE(str);
824
+ if (coderange == RUBY_ENC_CODERANGE_UNKNOWN) {
825
+ coderange = rb_enc_str_coderange(str);
826
+ }
827
+ return coderange;
828
+ }
829
+
822
830
  static inline bool valid_json_string_p(VALUE str)
823
831
  {
824
- int coderange = rb_enc_str_coderange(str);
832
+ int coderange = json_str_coderange(str);
825
833
 
826
834
  if (RB_LIKELY(coderange == ENC_CODERANGE_7BIT)) {
827
835
  return true;
@@ -834,12 +842,8 @@ static inline bool valid_json_string_p(VALUE str)
834
842
  return false;
835
843
  }
836
844
 
837
- static inline VALUE ensure_valid_encoding(struct generate_json_data *data, VALUE str, bool as_json_called, bool is_key)
845
+ NOINLINE(static) VALUE convert_invalid_encoding(struct generate_json_data *data, VALUE str, bool as_json_called, bool is_key)
838
846
  {
839
- if (RB_LIKELY(valid_json_string_p(str))) {
840
- return str;
841
- }
842
-
843
847
  if (!as_json_called && data->state->strict && RTEST(data->state->as_json)) {
844
848
  VALUE coerced_str = json_call_as_json(data->state, str, Qfalse);
845
849
  if (coerced_str != str) {
@@ -875,6 +879,16 @@ static inline VALUE ensure_valid_encoding(struct generate_json_data *data, VALUE
875
879
  return rb_rescue(encode_json_string_try, str, encode_json_string_rescue, str);
876
880
  }
877
881
 
882
+ ALWAYS_INLINE(static) VALUE ensure_valid_encoding(struct generate_json_data *data, VALUE str, bool as_json_called, bool is_key)
883
+ {
884
+ if (RB_LIKELY(valid_json_string_p(str))) {
885
+ return str;
886
+ }
887
+ else {
888
+ return convert_invalid_encoding(data, str, as_json_called, is_key);
889
+ }
890
+ }
891
+
878
892
  static void raw_generate_json_string(FBuffer *buffer, struct generate_json_data *data, VALUE obj)
879
893
  {
880
894
  fbuffer_append_char(buffer, '"');
@@ -893,7 +907,7 @@ static void raw_generate_json_string(FBuffer *buffer, struct generate_json_data
893
907
  search.chunk_end = NULL;
894
908
  #endif /* HAVE_SIMD */
895
909
 
896
- switch (rb_enc_str_coderange(obj)) {
910
+ switch (json_str_coderange(obj)) {
897
911
  case ENC_CODERANGE_7BIT:
898
912
  case ENC_CODERANGE_VALID:
899
913
  if (RB_UNLIKELY(data->state->ascii_only)) {
@@ -364,6 +364,7 @@ typedef struct JSON_ParserStateStruct {
364
364
  rvalue_cache name_cache;
365
365
  int in_array;
366
366
  int current_nesting;
367
+ unsigned int emitted_deprecations;
367
368
  } JSON_ParserState;
368
369
 
369
370
  static inline size_t rest(JSON_ParserState *state) {
@@ -945,7 +946,12 @@ static inline VALUE json_decode_object(JSON_ParserState *state, JSON_ParserConfi
945
946
  case JSON_IGNORE:
946
947
  break;
947
948
  case JSON_DEPRECATED:
948
- emit_duplicate_key_warning(state, json_find_duplicated_key(count, pairs));
949
+ // Only emit the first few deprecations to avoid spamming.
950
+ if (state->emitted_deprecations < 5) {
951
+ emit_duplicate_key_warning(state, json_find_duplicated_key(count, pairs));
952
+ state->emitted_deprecations++;
953
+ }
954
+
949
955
  break;
950
956
  case JSON_RAISE:
951
957
  raise_duplicate_key_error(state, json_find_duplicated_key(count, pairs));
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.19.4'
4
+ VERSION = '2.19.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.19.4
4
+ version: 2.19.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank