json 2.7.1 → 2.7.2

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: 6d39ddfc605399a55f202bd106776ede02812c232d813469165dfd9c06dbea5d
4
- data.tar.gz: d168c4f8aa5fe5f13e570e454c997fb91f6946ce8b339b0ef3477486edd8e99d
3
+ metadata.gz: 1ae811d90e98bbf8438c5abff24a9eabd5ef9c929115c14d3616a0c23f3a3fa2
4
+ data.tar.gz: eaa6afeb5ed814f5272bf54172b98ab217b26f850cb91d6fb081a9551237030c
5
5
  SHA512:
6
- metadata.gz: 3511a0cfd5365e476b39181201b0cd4ea8d415774ca524958955647bbeb9db0ddf5bbafae8f816fbb5b0459d643aa6345c63d5f3ec9443cd67c15cea50c0db57
7
- data.tar.gz: f015ec65ce58d4d946626162d29af7e24d26689fde3162b07b7a7b45d2f90049d676d8d1c22127ae1b7a6fdfb1926a80cb865330b9da458b700682d7d626b1b0
6
+ metadata.gz: c4119c5fdb66b553ee50cab0185cdec0ff7b09f102cfec8faa28efe2a6042d1e5cb46ada853afdc47b76707b5b180e0f68fb039e08e329935434716e2419b8e1
7
+ data.tar.gz: f7d69e1e729e4b37687358bd6ebf81e8909fe4418bfff5c8a2d676b070d6af979146d0b18c01820d5bd4a7f567a62cbb90d0e164e96d05c0e99d9968657467c0
data/README.md CHANGED
@@ -140,15 +140,6 @@ JSON JSON(1..10) # => 1..10
140
140
  To find out how to add JSON support to other or your own classes, read the
141
141
  section "More Examples" below.
142
142
 
143
- To get the best compatibility to rails' JSON implementation, you can
144
-
145
- ```ruby
146
- require 'json/add/rails'
147
- ```
148
-
149
- Both of the additions attempt to require `'json'` (like above) first, if it has
150
- not been required yet.
151
-
152
143
  ## Serializing exceptions
153
144
 
154
145
  The JSON module doesn't extend `Exception` by default. If you convert an `Exception`
@@ -867,7 +867,7 @@ json_object_i(VALUE key, VALUE val, VALUE _arg)
867
867
  if (klass == rb_cString) {
868
868
  key_to_s = key;
869
869
  } else if (klass == rb_cSymbol) {
870
- key_to_s = rb_id2str(SYM2ID(key));
870
+ key_to_s = rb_sym2str(key);
871
871
  } else {
872
872
  key_to_s = rb_funcall(key, i_to_s, 0);
873
873
  }
@@ -892,7 +892,6 @@ static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
892
892
  struct hash_foreach_arg arg;
893
893
 
894
894
  if (max_nesting != 0 && depth > max_nesting) {
895
- fbuffer_free(buffer);
896
895
  rb_raise(eNestingError, "nesting of %ld is too deep", --state->depth);
897
896
  }
898
897
  fbuffer_append_char(buffer, '{');
@@ -927,7 +926,6 @@ static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
927
926
  long depth = ++state->depth;
928
927
  int i, j;
929
928
  if (max_nesting != 0 && depth > max_nesting) {
930
- fbuffer_free(buffer);
931
929
  rb_raise(eNestingError, "nesting of %ld is too deep", --state->depth);
932
930
  }
933
931
  fbuffer_append_char(buffer, '[');
@@ -1020,10 +1018,8 @@ static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
1020
1018
  VALUE tmp = rb_funcall(obj, i_to_s, 0);
1021
1019
  if (!allow_nan) {
1022
1020
  if (isinf(value)) {
1023
- fbuffer_free(buffer);
1024
1021
  rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(tmp));
1025
1022
  } else if (isnan(value)) {
1026
- fbuffer_free(buffer);
1027
1023
  rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(tmp));
1028
1024
  }
1029
1025
  }
@@ -1096,11 +1092,45 @@ static FBuffer *cState_prepare_buffer(VALUE self)
1096
1092
  return buffer;
1097
1093
  }
1098
1094
 
1095
+ struct generate_json_data {
1096
+ FBuffer *buffer;
1097
+ VALUE vstate;
1098
+ JSON_Generator_State *state;
1099
+ VALUE obj;
1100
+ };
1101
+
1102
+ static VALUE generate_json_try(VALUE d)
1103
+ {
1104
+ struct generate_json_data *data = (struct generate_json_data *)d;
1105
+
1106
+ generate_json(data->buffer, data->vstate, data->state, data->obj);
1107
+
1108
+ return Qnil;
1109
+ }
1110
+
1111
+ static VALUE generate_json_rescue(VALUE d, VALUE exc)
1112
+ {
1113
+ struct generate_json_data *data = (struct generate_json_data *)d;
1114
+ fbuffer_free(data->buffer);
1115
+
1116
+ rb_exc_raise(exc);
1117
+
1118
+ return Qundef;
1119
+ }
1120
+
1099
1121
  static VALUE cState_partial_generate(VALUE self, VALUE obj)
1100
1122
  {
1101
1123
  FBuffer *buffer = cState_prepare_buffer(self);
1102
1124
  GET_STATE(self);
1103
- generate_json(buffer, self, state, obj);
1125
+
1126
+ struct generate_json_data data = {
1127
+ .buffer = buffer,
1128
+ .vstate = self,
1129
+ .state = state,
1130
+ .obj = obj
1131
+ };
1132
+ rb_rescue(generate_json_try, (VALUE)&data, generate_json_rescue, (VALUE)&data);
1133
+
1104
1134
  return fbuffer_to_s(buffer);
1105
1135
  }
1106
1136
 
@@ -2,7 +2,10 @@
2
2
  unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
3
3
  require 'json'
4
4
  end
5
- require 'ostruct'
5
+ begin
6
+ require 'ostruct'
7
+ rescue LoadError
8
+ end
6
9
 
7
10
  class OpenStruct
8
11
 
@@ -48,4 +51,4 @@ class OpenStruct
48
51
  def to_json(*args)
49
52
  as_json.to_json(*args)
50
53
  end
51
- end
54
+ end if defined?(::OpenStruct)
data/lib/json/common.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  #frozen_string_literal: false
2
2
  require 'json/version'
3
- require 'json/generic_object'
4
3
 
5
4
  module JSON
5
+ autoload :GenericObject, 'json/generic_object'
6
+
6
7
  NOT_SET = Object.new.freeze
7
8
  private_constant :NOT_SET
8
9
 
@@ -1,5 +1,9 @@
1
1
  #frozen_string_literal: false
2
- require 'ostruct'
2
+ begin
3
+ require 'ostruct'
4
+ rescue LoadError
5
+ warn "JSON::GenericObject requires 'ostruct'. Please install it with `gem install ostruct`."
6
+ end
3
7
 
4
8
  module JSON
5
9
  class GenericObject < OpenStruct
@@ -67,5 +71,5 @@ module JSON
67
71
  def to_json(*a)
68
72
  as_json.to_json(*a)
69
73
  end
70
- end
74
+ end if defined?(::OpenStruct)
71
75
  end
data/lib/json/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
  module JSON
3
3
  # JSON version
4
- VERSION = '2.7.1'
4
+ VERSION = '2.7.2'
5
5
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
6
6
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
7
7
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-12-05 00:00:00.000000000 Z
10
+ date: 2024-04-04 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: This is a JSON implementation as a Ruby extension in C.
14
13
  email: flori@ping.de
@@ -67,7 +66,6 @@ metadata:
67
66
  homepage_uri: https://flori.github.io/json
68
67
  source_code_uri: https://github.com/flori/json
69
68
  wiki_uri: https://github.com/flori/json/wiki
70
- post_install_message:
71
69
  rdoc_options:
72
70
  - "--title"
73
71
  - JSON implementation for Ruby
@@ -86,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
84
  - !ruby/object:Gem::Version
87
85
  version: '0'
88
86
  requirements: []
89
- rubygems_version: 3.5.0.dev
90
- signing_key:
87
+ rubygems_version: 3.6.0.dev
91
88
  specification_version: 4
92
89
  summary: JSON Implementation for Ruby
93
90
  test_files: []