json 2.6.3 → 2.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +46 -0
- data/README.md +4 -13
- data/ext/json/ext/generator/generator.c +120 -25
- data/ext/json/ext/generator/generator.h +8 -5
- data/ext/json/ext/parser/parser.c +1828 -2964
- data/ext/json/ext/parser/parser.rl +79 -94
- data/json.gemspec +7 -6
- data/lib/json/add/bigdecimal.rb +37 -8
- data/lib/json/add/complex.rb +28 -5
- data/lib/json/add/date.rb +26 -6
- data/lib/json/add/date_time.rb +25 -8
- data/lib/json/add/exception.rb +24 -6
- data/lib/json/add/ostruct.rb +31 -8
- data/lib/json/add/range.rb +32 -7
- data/lib/json/add/rational.rb +27 -5
- data/lib/json/add/regexp.rb +25 -7
- data/lib/json/add/set.rb +25 -6
- data/lib/json/add/struct.rb +28 -6
- data/lib/json/add/symbol.rb +27 -4
- data/lib/json/add/time.rb +26 -5
- data/lib/json/common.rb +29 -34
- data/lib/json/generic_object.rb +6 -2
- data/lib/json/pure/generator.rb +62 -28
- data/lib/json/version.rb +1 -1
- data/lib/json.rb +9 -0
- metadata +6 -10
- data/VERSION +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ae811d90e98bbf8438c5abff24a9eabd5ef9c929115c14d3616a0c23f3a3fa2
|
4
|
+
data.tar.gz: eaa6afeb5ed814f5272bf54172b98ab217b26f850cb91d6fb081a9551237030c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4119c5fdb66b553ee50cab0185cdec0ff7b09f102cfec8faa28efe2a6042d1e5cb46ada853afdc47b76707b5b180e0f68fb039e08e329935434716e2419b8e1
|
7
|
+
data.tar.gz: f7d69e1e729e4b37687358bd6ebf81e8909fe4418bfff5c8a2d676b070d6af979146d0b18c01820d5bd4a7f567a62cbb90d0e164e96d05c0e99d9968657467c0
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,38 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
### 2023-12-05 (2.7.1)
|
4
|
+
|
5
|
+
* JSON.dump: handle unenclosed hashes regression #554
|
6
|
+
* Overload kwargs in JSON.dump #556
|
7
|
+
* [DOC] RDoc for additions #557
|
8
|
+
* Fix JSON.dump overload combination #558
|
9
|
+
|
10
|
+
### 2023-12-01 (2.7.0)
|
11
|
+
|
12
|
+
* Add a strict option to Generator #519
|
13
|
+
* `escape_slash` option was renamed as `script_safe` and now also escape U+2028 and U+2029. `escape_slash` is now an alias of `script_safe` #525
|
14
|
+
* Remove unnecessary initialization of create_id in JSON.parse() #454
|
15
|
+
* Improvements to Hash#to_json in pure implementation generator #203
|
16
|
+
* Use ruby_xfree to free buffers #518
|
17
|
+
* Fix "unexpected token" offset for Infinity #507
|
18
|
+
* Avoid using deprecated BigDecimal.new on JRuby #546
|
19
|
+
* Removed code for Ruby 1.8 #540
|
20
|
+
* Rename JSON::ParseError to JSON:ParserError #530
|
21
|
+
* Call super in included hook #486
|
22
|
+
* JRuby requires a minimum of Java 8 #516
|
23
|
+
* Always indent even if empty #517
|
24
|
+
|
25
|
+
### 2022-11-30 (2.6.3)
|
26
|
+
|
27
|
+
* bugfix json/pure mixing escaped with literal unicode raises Encoding::CompatibilityError #483
|
28
|
+
* Stop including the parser source __LINE__ in exceptions #470
|
29
|
+
|
30
|
+
### 2022-11-17 (2.6.2)
|
31
|
+
|
32
|
+
* Remove unknown keyword arg from DateTime.parse #488
|
33
|
+
* Ignore java artifacts by @hsbt #489
|
34
|
+
* Fix parser bug for empty string allocation #496
|
35
|
+
|
3
36
|
### 2021-10-24 (2.6.1)
|
4
37
|
|
5
38
|
* Restore version.rb with 2.6.1
|
@@ -105,6 +138,19 @@
|
|
105
138
|
I changed these mentions to be consistent with the Ruby license setting in
|
106
139
|
the gemspec files which were already correct now.
|
107
140
|
|
141
|
+
## 2017-01-13 (1.8.6)
|
142
|
+
* Be compatible with ancient ruby 1.8 (maybe?)
|
143
|
+
|
144
|
+
## 2015-09-11 (1.8.5)
|
145
|
+
* Be compatible with ruby 2.4.0
|
146
|
+
* There were still some mentions of dual GPL licensing in the source, but JSON
|
147
|
+
has just the Ruby license that itself includes an explicit dual-licensing
|
148
|
+
clause that allows covered software to be distributed under the terms of
|
149
|
+
the Simplified BSD License instead for all ruby versions >= 1.9.3. This is
|
150
|
+
however a GPL compatible license according to the Free Software Foundation.
|
151
|
+
I changed these mentions to be consistent with the Ruby license setting in
|
152
|
+
the gemspec files which were already correct now.
|
153
|
+
|
108
154
|
## 2015-06-01 (1.8.3)
|
109
155
|
* Fix potential memory leak, thx to nobu.
|
110
156
|
|
data/README.md
CHANGED
@@ -12,8 +12,7 @@ will be two variants available:
|
|
12
12
|
extensions, which are both part of the ruby standard library.
|
13
13
|
* The quite a bit faster native extension variant, which is in parts
|
14
14
|
implemented in C or Java and comes with its own unicode conversion
|
15
|
-
functions and a parser generated by the
|
16
|
-
http://www.complang.org/ragel/ .
|
15
|
+
functions and a parser generated by the [Ragel] state machine compiler.
|
17
16
|
|
18
17
|
Both variants of the JSON generator generate UTF-8 character sequences by
|
19
18
|
default. If an :ascii\_only option with a true value is given, they escape all
|
@@ -71,8 +70,7 @@ with:
|
|
71
70
|
## Compiling the extensions yourself
|
72
71
|
|
73
72
|
If you want to create the `parser.c` file from its `parser.rl` file or draw nice
|
74
|
-
graphviz images of the state machines, you need
|
75
|
-
http://www.complang.org/ragel/
|
73
|
+
graphviz images of the state machines, you need [Ragel].
|
76
74
|
|
77
75
|
## Usage
|
78
76
|
|
@@ -142,15 +140,6 @@ JSON JSON(1..10) # => 1..10
|
|
142
140
|
To find out how to add JSON support to other or your own classes, read the
|
143
141
|
section "More Examples" below.
|
144
142
|
|
145
|
-
To get the best compatibility to rails' JSON implementation, you can
|
146
|
-
|
147
|
-
```ruby
|
148
|
-
require 'json/add/rails'
|
149
|
-
```
|
150
|
-
|
151
|
-
Both of the additions attempt to require `'json'` (like above) first, if it has
|
152
|
-
not been required yet.
|
153
|
-
|
154
143
|
## Serializing exceptions
|
155
144
|
|
156
145
|
The JSON module doesn't extend `Exception` by default. If you convert an `Exception`
|
@@ -423,3 +412,5 @@ The latest version of this library can be downloaded at
|
|
423
412
|
Online Documentation should be located at
|
424
413
|
|
425
414
|
* https://www.rubydoc.info/gems/json
|
415
|
+
|
416
|
+
[Ragel]: http://www.colm.net/open-source/ragel/
|
@@ -16,7 +16,7 @@ static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before,
|
|
16
16
|
i_object_nl, i_array_nl, i_max_nesting, i_allow_nan, i_ascii_only,
|
17
17
|
i_pack, i_unpack, i_create_id, i_extend, i_key_p,
|
18
18
|
i_aref, i_send, i_respond_to_p, i_match, i_keys, i_depth,
|
19
|
-
i_buffer_initial_length, i_dup, i_escape_slash;
|
19
|
+
i_buffer_initial_length, i_dup, i_script_safe, i_escape_slash, i_strict;
|
20
20
|
|
21
21
|
/*
|
22
22
|
* Copyright 2001-2004 Unicode, Inc.
|
@@ -124,7 +124,7 @@ static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16
|
|
124
124
|
|
125
125
|
/* Converts string to a JSON string in FBuffer buffer, where all but the ASCII
|
126
126
|
* and control characters are JSON escaped. */
|
127
|
-
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char
|
127
|
+
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char script_safe)
|
128
128
|
{
|
129
129
|
const UTF8 *source = (UTF8 *) RSTRING_PTR(string);
|
130
130
|
const UTF8 *sourceEnd = source + RSTRING_LEN(string);
|
@@ -175,7 +175,7 @@ static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char escap
|
|
175
175
|
fbuffer_append(buffer, "\\\"", 2);
|
176
176
|
break;
|
177
177
|
case '/':
|
178
|
-
if(
|
178
|
+
if(script_safe) {
|
179
179
|
fbuffer_append(buffer, "\\/", 2);
|
180
180
|
break;
|
181
181
|
}
|
@@ -228,7 +228,7 @@ static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char escap
|
|
228
228
|
* characters required by the JSON standard are JSON escaped. The remaining
|
229
229
|
* characters (should be UTF8) are just passed through and appended to the
|
230
230
|
* result. */
|
231
|
-
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char
|
231
|
+
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char script_safe)
|
232
232
|
{
|
233
233
|
const char *ptr = RSTRING_PTR(string), *p;
|
234
234
|
unsigned long len = RSTRING_LEN(string), start = 0, end = 0;
|
@@ -280,7 +280,7 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char escape_slas
|
|
280
280
|
escape_len = 2;
|
281
281
|
break;
|
282
282
|
case '/':
|
283
|
-
if(
|
283
|
+
if(script_safe) {
|
284
284
|
escape = "\\/";
|
285
285
|
escape_len = 2;
|
286
286
|
break;
|
@@ -294,6 +294,22 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char escape_slas
|
|
294
294
|
rb_raise(rb_path2class("JSON::GeneratorError"),
|
295
295
|
"partial character in source, but hit end");
|
296
296
|
}
|
297
|
+
|
298
|
+
if (script_safe && c == 0xE2) {
|
299
|
+
unsigned char c2 = (unsigned char) *(p+1);
|
300
|
+
unsigned char c3 = (unsigned char) *(p+2);
|
301
|
+
if (c2 == 0x80 && (c3 == 0xA8 || c3 == 0xA9)) {
|
302
|
+
fbuffer_append(buffer, ptr + start, end - start);
|
303
|
+
start = end = (end + clen);
|
304
|
+
if (c3 == 0xA8) {
|
305
|
+
fbuffer_append(buffer, "\\u2028", 6);
|
306
|
+
} else {
|
307
|
+
fbuffer_append(buffer, "\\u2029", 6);
|
308
|
+
}
|
309
|
+
continue;
|
310
|
+
}
|
311
|
+
}
|
312
|
+
|
297
313
|
if (!isLegalUTF8((UTF8 *) p, clen)) {
|
298
314
|
rb_raise(rb_path2class("JSON::GeneratorError"),
|
299
315
|
"source sequence is illegal/malformed utf-8");
|
@@ -478,6 +494,7 @@ static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self)
|
|
478
494
|
*/
|
479
495
|
static VALUE mString_included_s(VALUE self, VALUE modul) {
|
480
496
|
VALUE result = rb_funcall(modul, i_extend, 1, mString_Extend);
|
497
|
+
rb_call_super(1, &modul);
|
481
498
|
return result;
|
482
499
|
}
|
483
500
|
|
@@ -726,8 +743,14 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
726
743
|
state->allow_nan = RTEST(tmp);
|
727
744
|
tmp = rb_hash_aref(opts, ID2SYM(i_ascii_only));
|
728
745
|
state->ascii_only = RTEST(tmp);
|
729
|
-
tmp = rb_hash_aref(opts, ID2SYM(
|
730
|
-
state->
|
746
|
+
tmp = rb_hash_aref(opts, ID2SYM(i_script_safe));
|
747
|
+
state->script_safe = RTEST(tmp);
|
748
|
+
if (!state->script_safe) {
|
749
|
+
tmp = rb_hash_aref(opts, ID2SYM(i_escape_slash));
|
750
|
+
state->script_safe = RTEST(tmp);
|
751
|
+
}
|
752
|
+
tmp = rb_hash_aref(opts, ID2SYM(i_strict));
|
753
|
+
state->strict = RTEST(tmp);
|
731
754
|
return self;
|
732
755
|
}
|
733
756
|
|
@@ -762,7 +785,8 @@ static VALUE cState_to_h(VALUE self)
|
|
762
785
|
rb_hash_aset(result, ID2SYM(i_allow_nan), state->allow_nan ? Qtrue : Qfalse);
|
763
786
|
rb_hash_aset(result, ID2SYM(i_ascii_only), state->ascii_only ? Qtrue : Qfalse);
|
764
787
|
rb_hash_aset(result, ID2SYM(i_max_nesting), LONG2FIX(state->max_nesting));
|
765
|
-
rb_hash_aset(result, ID2SYM(
|
788
|
+
rb_hash_aset(result, ID2SYM(i_script_safe), state->script_safe ? Qtrue : Qfalse);
|
789
|
+
rb_hash_aset(result, ID2SYM(i_strict), state->strict ? Qtrue : Qfalse);
|
766
790
|
rb_hash_aset(result, ID2SYM(i_depth), LONG2FIX(state->depth));
|
767
791
|
rb_hash_aset(result, ID2SYM(i_buffer_initial_length), LONG2FIX(state->buffer_initial_length));
|
768
792
|
return result;
|
@@ -843,7 +867,7 @@ json_object_i(VALUE key, VALUE val, VALUE _arg)
|
|
843
867
|
if (klass == rb_cString) {
|
844
868
|
key_to_s = key;
|
845
869
|
} else if (klass == rb_cSymbol) {
|
846
|
-
key_to_s =
|
870
|
+
key_to_s = rb_sym2str(key);
|
847
871
|
} else {
|
848
872
|
key_to_s = rb_funcall(key, i_to_s, 0);
|
849
873
|
}
|
@@ -868,7 +892,6 @@ static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|
868
892
|
struct hash_foreach_arg arg;
|
869
893
|
|
870
894
|
if (max_nesting != 0 && depth > max_nesting) {
|
871
|
-
fbuffer_free(buffer);
|
872
895
|
rb_raise(eNestingError, "nesting of %ld is too deep", --state->depth);
|
873
896
|
}
|
874
897
|
fbuffer_append_char(buffer, '{');
|
@@ -903,7 +926,6 @@ static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
|
|
903
926
|
long depth = ++state->depth;
|
904
927
|
int i, j;
|
905
928
|
if (max_nesting != 0 && depth > max_nesting) {
|
906
|
-
fbuffer_free(buffer);
|
907
929
|
rb_raise(eNestingError, "nesting of %ld is too deep", --state->depth);
|
908
930
|
}
|
909
931
|
fbuffer_append_char(buffer, '[');
|
@@ -947,9 +969,9 @@ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|
947
969
|
}
|
948
970
|
#endif
|
949
971
|
if (state->ascii_only) {
|
950
|
-
convert_UTF8_to_JSON_ASCII(buffer, obj, state->
|
972
|
+
convert_UTF8_to_JSON_ASCII(buffer, obj, state->script_safe);
|
951
973
|
} else {
|
952
|
-
convert_UTF8_to_JSON(buffer, obj, state->
|
974
|
+
convert_UTF8_to_JSON(buffer, obj, state->script_safe);
|
953
975
|
}
|
954
976
|
fbuffer_append_char(buffer, '"');
|
955
977
|
}
|
@@ -996,10 +1018,8 @@ static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
|
|
996
1018
|
VALUE tmp = rb_funcall(obj, i_to_s, 0);
|
997
1019
|
if (!allow_nan) {
|
998
1020
|
if (isinf(value)) {
|
999
|
-
fbuffer_free(buffer);
|
1000
1021
|
rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(tmp));
|
1001
1022
|
} else if (isnan(value)) {
|
1002
|
-
fbuffer_free(buffer);
|
1003
1023
|
rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(tmp));
|
1004
1024
|
}
|
1005
1025
|
}
|
@@ -1028,6 +1048,8 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
|
|
1028
1048
|
generate_json_bignum(buffer, Vstate, state, obj);
|
1029
1049
|
} else if (klass == rb_cFloat) {
|
1030
1050
|
generate_json_float(buffer, Vstate, state, obj);
|
1051
|
+
} else if (state->strict) {
|
1052
|
+
rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(CLASS_OF(obj)));
|
1031
1053
|
} else if (rb_respond_to(obj, i_to_json)) {
|
1032
1054
|
tmp = rb_funcall(obj, i_to_json, 1, Vstate);
|
1033
1055
|
Check_Type(tmp, T_STRING);
|
@@ -1070,11 +1092,45 @@ static FBuffer *cState_prepare_buffer(VALUE self)
|
|
1070
1092
|
return buffer;
|
1071
1093
|
}
|
1072
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
|
+
|
1073
1121
|
static VALUE cState_partial_generate(VALUE self, VALUE obj)
|
1074
1122
|
{
|
1075
1123
|
FBuffer *buffer = cState_prepare_buffer(self);
|
1076
1124
|
GET_STATE(self);
|
1077
|
-
|
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
|
+
|
1078
1134
|
return fbuffer_to_s(buffer);
|
1079
1135
|
}
|
1080
1136
|
|
@@ -1390,27 +1446,58 @@ static VALUE cState_max_nesting_set(VALUE self, VALUE depth)
|
|
1390
1446
|
}
|
1391
1447
|
|
1392
1448
|
/*
|
1393
|
-
* call-seq:
|
1449
|
+
* call-seq: script_safe
|
1394
1450
|
*
|
1395
1451
|
* If this boolean is true, the forward slashes will be escaped in
|
1396
1452
|
* the json output.
|
1397
1453
|
*/
|
1398
|
-
static VALUE
|
1454
|
+
static VALUE cState_script_safe(VALUE self)
|
1399
1455
|
{
|
1400
1456
|
GET_STATE(self);
|
1401
|
-
return state->
|
1457
|
+
return state->script_safe ? Qtrue : Qfalse;
|
1402
1458
|
}
|
1403
1459
|
|
1404
1460
|
/*
|
1405
|
-
* call-seq:
|
1461
|
+
* call-seq: script_safe=(enable)
|
1406
1462
|
*
|
1407
1463
|
* This sets whether or not the forward slashes will be escaped in
|
1408
1464
|
* the json output.
|
1409
1465
|
*/
|
1410
|
-
static VALUE
|
1466
|
+
static VALUE cState_script_safe_set(VALUE self, VALUE enable)
|
1467
|
+
{
|
1468
|
+
GET_STATE(self);
|
1469
|
+
state->script_safe = RTEST(enable);
|
1470
|
+
return Qnil;
|
1471
|
+
}
|
1472
|
+
|
1473
|
+
/*
|
1474
|
+
* call-seq: strict
|
1475
|
+
*
|
1476
|
+
* If this boolean is false, types unsupported by the JSON format will
|
1477
|
+
* be serialized as strings.
|
1478
|
+
* If this boolean is true, types unsupported by the JSON format will
|
1479
|
+
* raise a JSON::GeneratorError.
|
1480
|
+
*/
|
1481
|
+
static VALUE cState_strict(VALUE self)
|
1482
|
+
{
|
1483
|
+
GET_STATE(self);
|
1484
|
+
return state->strict ? Qtrue : Qfalse;
|
1485
|
+
}
|
1486
|
+
|
1487
|
+
/*
|
1488
|
+
* call-seq: strict=(enable)
|
1489
|
+
*
|
1490
|
+
* This sets whether or not to serialize types unsupported by the
|
1491
|
+
* JSON format as strings.
|
1492
|
+
* If this boolean is false, types unsupported by the JSON format will
|
1493
|
+
* be serialized as strings.
|
1494
|
+
* If this boolean is true, types unsupported by the JSON format will
|
1495
|
+
* raise a JSON::GeneratorError.
|
1496
|
+
*/
|
1497
|
+
static VALUE cState_strict_set(VALUE self, VALUE enable)
|
1411
1498
|
{
|
1412
1499
|
GET_STATE(self);
|
1413
|
-
state->
|
1500
|
+
state->strict = RTEST(enable);
|
1414
1501
|
return Qnil;
|
1415
1502
|
}
|
1416
1503
|
|
@@ -1530,9 +1617,15 @@ void Init_generator(void)
|
|
1530
1617
|
rb_define_method(cState, "array_nl=", cState_array_nl_set, 1);
|
1531
1618
|
rb_define_method(cState, "max_nesting", cState_max_nesting, 0);
|
1532
1619
|
rb_define_method(cState, "max_nesting=", cState_max_nesting_set, 1);
|
1533
|
-
rb_define_method(cState, "
|
1534
|
-
rb_define_method(cState, "
|
1535
|
-
rb_define_method(cState, "
|
1620
|
+
rb_define_method(cState, "script_safe", cState_script_safe, 0);
|
1621
|
+
rb_define_method(cState, "script_safe?", cState_script_safe, 0);
|
1622
|
+
rb_define_method(cState, "script_safe=", cState_script_safe_set, 1);
|
1623
|
+
rb_define_alias(cState, "escape_slash", "script_safe");
|
1624
|
+
rb_define_alias(cState, "escape_slash?", "script_safe?");
|
1625
|
+
rb_define_alias(cState, "escape_slash=", "script_safe=");
|
1626
|
+
rb_define_method(cState, "strict", cState_strict, 0);
|
1627
|
+
rb_define_method(cState, "strict?", cState_strict, 0);
|
1628
|
+
rb_define_method(cState, "strict=", cState_strict_set, 1);
|
1536
1629
|
rb_define_method(cState, "check_circular?", cState_check_circular_p, 0);
|
1537
1630
|
rb_define_method(cState, "allow_nan?", cState_allow_nan_p, 0);
|
1538
1631
|
rb_define_method(cState, "ascii_only?", cState_ascii_only_p, 0);
|
@@ -1589,7 +1682,9 @@ void Init_generator(void)
|
|
1589
1682
|
i_object_nl = rb_intern("object_nl");
|
1590
1683
|
i_array_nl = rb_intern("array_nl");
|
1591
1684
|
i_max_nesting = rb_intern("max_nesting");
|
1685
|
+
i_script_safe = rb_intern("script_safe");
|
1592
1686
|
i_escape_slash = rb_intern("escape_slash");
|
1687
|
+
i_strict = rb_intern("strict");
|
1593
1688
|
i_allow_nan = rb_intern("allow_nan");
|
1594
1689
|
i_ascii_only = rb_intern("ascii_only");
|
1595
1690
|
i_depth = rb_intern("depth");
|
@@ -49,8 +49,8 @@ static const UTF32 halfMask = 0x3FFUL;
|
|
49
49
|
static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length);
|
50
50
|
static void unicode_escape(char *buf, UTF16 character);
|
51
51
|
static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
|
52
|
-
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char
|
53
|
-
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char
|
52
|
+
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char script_safe);
|
53
|
+
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char script_safe);
|
54
54
|
static char *fstrndup(const char *ptr, unsigned long len);
|
55
55
|
|
56
56
|
/* ruby api and some helpers */
|
@@ -72,7 +72,8 @@ typedef struct JSON_Generator_StateStruct {
|
|
72
72
|
long max_nesting;
|
73
73
|
char allow_nan;
|
74
74
|
char ascii_only;
|
75
|
-
char
|
75
|
+
char script_safe;
|
76
|
+
char strict;
|
76
77
|
long depth;
|
77
78
|
long buffer_initial_length;
|
78
79
|
} JSON_Generator_State;
|
@@ -151,8 +152,10 @@ static VALUE cState_allow_nan_p(VALUE self);
|
|
151
152
|
static VALUE cState_ascii_only_p(VALUE self);
|
152
153
|
static VALUE cState_depth(VALUE self);
|
153
154
|
static VALUE cState_depth_set(VALUE self, VALUE depth);
|
154
|
-
static VALUE
|
155
|
-
static VALUE
|
155
|
+
static VALUE cState_script_safe(VALUE self);
|
156
|
+
static VALUE cState_script_safe_set(VALUE self, VALUE depth);
|
157
|
+
static VALUE cState_strict(VALUE self);
|
158
|
+
static VALUE cState_strict_set(VALUE self, VALUE strict);
|
156
159
|
static FBuffer *cState_prepare_buffer(VALUE self);
|
157
160
|
#ifndef ZALLOC
|
158
161
|
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
|