json 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of json might be problematic. Click here for more details.
- data/CHANGES +16 -0
- data/Rakefile +80 -75
- data/TODO +1 -1
- data/VERSION +1 -1
- data/bin/edit_json.rb +11 -11
- data/data/prototype.js +2764 -1095
- data/ext/json/ext/generator/generator.c +17 -4
- data/ext/json/ext/parser/parser.c +95 -73
- data/ext/json/ext/parser/parser.rl +34 -12
- data/lib/json.rb +14 -12
- data/lib/json/add/core.rb +2 -1
- data/lib/json/add/rails.rb +6 -0
- data/lib/json/common.rb +9 -0
- data/lib/json/editor.rb +1363 -1293
- data/lib/json/pure/parser.rb +7 -3
- data/lib/json/version.rb +1 -1
- data/tests/runner.rb +2 -0
- data/tests/test_json_addition.rb +19 -0
- data/tests/test_json_rails.rb +114 -0
- metadata +87 -85
@@ -9,7 +9,7 @@
|
|
9
9
|
#define check_max_nesting(state, depth) do { \
|
10
10
|
long current_nesting = 1 + depth; \
|
11
11
|
if (state->max_nesting != 0 && current_nesting > state->max_nesting) \
|
12
|
-
rb_raise(eNestingError, "nesting of %
|
12
|
+
rb_raise(eNestingError, "nesting of %ld is too deep", current_nesting); \
|
13
13
|
} while (0);
|
14
14
|
|
15
15
|
static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
|
@@ -69,6 +69,7 @@ static int hash_to_json_state_i(VALUE key, VALUE value, VALUE Vstate)
|
|
69
69
|
rb_str_buf_append(buf, rb_str_times(state->indent, Vdepth));
|
70
70
|
}
|
71
71
|
json = rb_funcall(rb_funcall(key, i_to_s, 0), i_to_json, 2, Vstate, Vdepth);
|
72
|
+
Check_Type(json, T_STRING);
|
72
73
|
rb_str_buf_append(buf, json);
|
73
74
|
OBJ_INFECT(buf, json);
|
74
75
|
if (RSTRING_LEN(state->space_before)) {
|
@@ -77,6 +78,7 @@ static int hash_to_json_state_i(VALUE key, VALUE value, VALUE Vstate)
|
|
77
78
|
rb_str_buf_cat2(buf, ":");
|
78
79
|
if (RSTRING_LEN(state->space)) rb_str_buf_append(buf, state->space);
|
79
80
|
json = rb_funcall(value, i_to_json, 2, Vstate, Vdepth);
|
81
|
+
Check_Type(json, T_STRING);
|
80
82
|
state->flag = 1;
|
81
83
|
rb_str_buf_append(buf, json);
|
82
84
|
OBJ_INFECT(buf, json);
|
@@ -113,10 +115,12 @@ static int hash_to_json_i(VALUE key, VALUE value, VALUE buf)
|
|
113
115
|
if (key == Qundef) return ST_CONTINUE;
|
114
116
|
if (RSTRING_LEN(buf) > 1) rb_str_buf_cat2(buf, ",");
|
115
117
|
tmp = rb_funcall(rb_funcall(key, i_to_s, 0), i_to_json, 0);
|
118
|
+
Check_Type(tmp, T_STRING);
|
116
119
|
rb_str_buf_append(buf, tmp);
|
117
120
|
OBJ_INFECT(buf, tmp);
|
118
121
|
rb_str_buf_cat2(buf, ":");
|
119
122
|
tmp = rb_funcall(value, i_to_json, 0);
|
123
|
+
Check_Type(tmp, T_STRING);
|
120
124
|
rb_str_buf_append(buf, tmp);
|
121
125
|
OBJ_INFECT(buf, tmp);
|
122
126
|
|
@@ -192,7 +196,9 @@ inline static VALUE mArray_json_transfrom(VALUE self, VALUE Vstate, VALUE Vdepth
|
|
192
196
|
OBJ_INFECT(result, element);
|
193
197
|
if (i > 0) rb_str_buf_append(result, delim);
|
194
198
|
rb_str_buf_append(result, shift);
|
195
|
-
|
199
|
+
element = rb_funcall(element, i_to_json, 2, Vstate, LONG2FIX(depth + 1));
|
200
|
+
Check_Type(element, T_STRING);
|
201
|
+
rb_str_buf_append(result, element);
|
196
202
|
}
|
197
203
|
if (RSTRING_LEN(state->array_nl)) {
|
198
204
|
rb_str_buf_append(result, state->array_nl);
|
@@ -213,7 +219,9 @@ inline static VALUE mArray_json_transfrom(VALUE self, VALUE Vstate, VALUE Vdepth
|
|
213
219
|
OBJ_INFECT(result, element);
|
214
220
|
if (i > 0) rb_str_buf_append(result, delim);
|
215
221
|
rb_str_buf_append(result, shift);
|
216
|
-
|
222
|
+
element = rb_funcall(element, i_to_json, 2, Vstate, LONG2FIX(depth + 1));
|
223
|
+
Check_Type(element, T_STRING);
|
224
|
+
rb_str_buf_append(result, element);
|
217
225
|
}
|
218
226
|
rb_str_buf_append(result, state->array_nl);
|
219
227
|
if (RSTRING_LEN(state->array_nl)) {
|
@@ -246,7 +254,9 @@ static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self) {
|
|
246
254
|
VALUE element = RARRAY_PTR(self)[i];
|
247
255
|
OBJ_INFECT(result, element);
|
248
256
|
if (i > 0) rb_str_buf_cat2(result, ",");
|
249
|
-
|
257
|
+
element = rb_funcall(element, i_to_json, 0);
|
258
|
+
Check_Type(element, T_STRING);
|
259
|
+
rb_str_buf_append(result, element);
|
250
260
|
}
|
251
261
|
rb_str_buf_cat2(result, "]");
|
252
262
|
} else {
|
@@ -787,6 +797,9 @@ static VALUE cState_forget(VALUE self, VALUE object)
|
|
787
797
|
return rb_hash_delete(state->seen, rb_obj_id(object));
|
788
798
|
}
|
789
799
|
|
800
|
+
/*
|
801
|
+
*
|
802
|
+
*/
|
790
803
|
void Init_generator()
|
791
804
|
{
|
792
805
|
mJSON = rb_define_module("JSON");
|
@@ -11,8 +11,8 @@
|
|
11
11
|
static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
|
12
12
|
static VALUE CNaN, CInfinity, CMinusInfinity;
|
13
13
|
|
14
|
-
static ID i_json_creatable_p, i_json_create, i_create_id,
|
15
|
-
i_allow_nan;
|
14
|
+
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
15
|
+
i_chr, i_max_nesting, i_allow_nan;
|
16
16
|
|
17
17
|
#define MinusInfinity "-Infinity"
|
18
18
|
|
@@ -386,11 +386,13 @@ case 26:
|
|
386
386
|
#line 114 "parser.rl"
|
387
387
|
|
388
388
|
if (cs >= JSON_object_first_final) {
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
389
|
+
if (RTEST(json->create_id)) {
|
390
|
+
VALUE klassname = rb_hash_aref(*result, json->create_id);
|
391
|
+
if (!NIL_P(klassname)) {
|
392
|
+
VALUE klass = rb_path2class(StringValueCStr(klassname));
|
393
|
+
if RTEST(rb_funcall(klass, i_json_creatable_p, 0)) {
|
394
|
+
*result = rb_funcall(klass, i_json_create, 1, *result);
|
395
|
+
}
|
394
396
|
}
|
395
397
|
}
|
396
398
|
return p + 1;
|
@@ -400,14 +402,14 @@ case 26:
|
|
400
402
|
}
|
401
403
|
|
402
404
|
|
403
|
-
#line
|
405
|
+
#line 406 "parser.c"
|
404
406
|
static const int JSON_value_start = 1;
|
405
407
|
static const int JSON_value_first_final = 21;
|
406
408
|
static const int JSON_value_error = 0;
|
407
409
|
|
408
410
|
static const int JSON_value_en_main = 1;
|
409
411
|
|
410
|
-
#line
|
412
|
+
#line 212 "parser.rl"
|
411
413
|
|
412
414
|
|
413
415
|
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -415,13 +417,13 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
415
417
|
int cs = EVIL;
|
416
418
|
|
417
419
|
|
418
|
-
#line
|
420
|
+
#line 421 "parser.c"
|
419
421
|
{
|
420
422
|
cs = JSON_value_start;
|
421
423
|
}
|
422
|
-
#line
|
424
|
+
#line 219 "parser.rl"
|
423
425
|
|
424
|
-
#line
|
426
|
+
#line 427 "parser.c"
|
425
427
|
{
|
426
428
|
if ( p == pe )
|
427
429
|
goto _out;
|
@@ -445,14 +447,14 @@ case 1:
|
|
445
447
|
st0:
|
446
448
|
goto _out0;
|
447
449
|
tr0:
|
448
|
-
#line
|
450
|
+
#line 160 "parser.rl"
|
449
451
|
{
|
450
452
|
char *np = JSON_parse_string(json, p, pe, result);
|
451
453
|
if (np == NULL) goto _out21; else {p = (( np))-1;}
|
452
454
|
}
|
453
455
|
goto st21;
|
454
456
|
tr2:
|
455
|
-
#line
|
457
|
+
#line 165 "parser.rl"
|
456
458
|
{
|
457
459
|
char *np;
|
458
460
|
if(pe > p + 9 && !strncmp(MinusInfinity, p, 9)) {
|
@@ -472,7 +474,7 @@ tr2:
|
|
472
474
|
}
|
473
475
|
goto st21;
|
474
476
|
tr5:
|
475
|
-
#line
|
477
|
+
#line 183 "parser.rl"
|
476
478
|
{
|
477
479
|
char *np;
|
478
480
|
json->current_nesting += 1;
|
@@ -482,7 +484,7 @@ tr5:
|
|
482
484
|
}
|
483
485
|
goto st21;
|
484
486
|
tr9:
|
485
|
-
#line
|
487
|
+
#line 191 "parser.rl"
|
486
488
|
{
|
487
489
|
char *np;
|
488
490
|
json->current_nesting += 1;
|
@@ -492,7 +494,7 @@ tr9:
|
|
492
494
|
}
|
493
495
|
goto st21;
|
494
496
|
tr16:
|
495
|
-
#line
|
497
|
+
#line 153 "parser.rl"
|
496
498
|
{
|
497
499
|
if (json->allow_nan) {
|
498
500
|
*result = CInfinity;
|
@@ -502,7 +504,7 @@ tr16:
|
|
502
504
|
}
|
503
505
|
goto st21;
|
504
506
|
tr18:
|
505
|
-
#line
|
507
|
+
#line 146 "parser.rl"
|
506
508
|
{
|
507
509
|
if (json->allow_nan) {
|
508
510
|
*result = CNaN;
|
@@ -512,19 +514,19 @@ tr18:
|
|
512
514
|
}
|
513
515
|
goto st21;
|
514
516
|
tr22:
|
515
|
-
#line
|
517
|
+
#line 140 "parser.rl"
|
516
518
|
{
|
517
519
|
*result = Qfalse;
|
518
520
|
}
|
519
521
|
goto st21;
|
520
522
|
tr25:
|
521
|
-
#line
|
523
|
+
#line 137 "parser.rl"
|
522
524
|
{
|
523
525
|
*result = Qnil;
|
524
526
|
}
|
525
527
|
goto st21;
|
526
528
|
tr28:
|
527
|
-
#line
|
529
|
+
#line 143 "parser.rl"
|
528
530
|
{
|
529
531
|
*result = Qtrue;
|
530
532
|
}
|
@@ -533,9 +535,9 @@ st21:
|
|
533
535
|
if ( ++p == pe )
|
534
536
|
goto _out21;
|
535
537
|
case 21:
|
536
|
-
#line
|
538
|
+
#line 199 "parser.rl"
|
537
539
|
{ goto _out21; }
|
538
|
-
#line
|
540
|
+
#line 541 "parser.c"
|
539
541
|
goto st0;
|
540
542
|
st2:
|
541
543
|
if ( ++p == pe )
|
@@ -695,7 +697,7 @@ case 20:
|
|
695
697
|
|
696
698
|
_out: {}
|
697
699
|
}
|
698
|
-
#line
|
700
|
+
#line 220 "parser.rl"
|
699
701
|
|
700
702
|
if (cs >= JSON_value_first_final) {
|
701
703
|
return p;
|
@@ -705,14 +707,14 @@ case 20:
|
|
705
707
|
}
|
706
708
|
|
707
709
|
|
708
|
-
#line
|
710
|
+
#line 711 "parser.c"
|
709
711
|
static const int JSON_integer_start = 1;
|
710
712
|
static const int JSON_integer_first_final = 5;
|
711
713
|
static const int JSON_integer_error = 0;
|
712
714
|
|
713
715
|
static const int JSON_integer_en_main = 1;
|
714
716
|
|
715
|
-
#line
|
717
|
+
#line 236 "parser.rl"
|
716
718
|
|
717
719
|
|
718
720
|
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -720,14 +722,14 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
720
722
|
int cs = EVIL;
|
721
723
|
|
722
724
|
|
723
|
-
#line
|
725
|
+
#line 726 "parser.c"
|
724
726
|
{
|
725
727
|
cs = JSON_integer_start;
|
726
728
|
}
|
727
|
-
#line
|
729
|
+
#line 243 "parser.rl"
|
728
730
|
json->memo = p;
|
729
731
|
|
730
|
-
#line
|
732
|
+
#line 733 "parser.c"
|
731
733
|
{
|
732
734
|
if ( p == pe )
|
733
735
|
goto _out;
|
@@ -760,14 +762,14 @@ case 3:
|
|
760
762
|
goto st0;
|
761
763
|
goto tr4;
|
762
764
|
tr4:
|
763
|
-
#line
|
765
|
+
#line 233 "parser.rl"
|
764
766
|
{ goto _out5; }
|
765
767
|
goto st5;
|
766
768
|
st5:
|
767
769
|
if ( ++p == pe )
|
768
770
|
goto _out5;
|
769
771
|
case 5:
|
770
|
-
#line
|
772
|
+
#line 773 "parser.c"
|
771
773
|
goto st0;
|
772
774
|
st4:
|
773
775
|
if ( ++p == pe )
|
@@ -785,7 +787,7 @@ case 4:
|
|
785
787
|
|
786
788
|
_out: {}
|
787
789
|
}
|
788
|
-
#line
|
790
|
+
#line 245 "parser.rl"
|
789
791
|
|
790
792
|
if (cs >= JSON_integer_first_final) {
|
791
793
|
long len = p - json->memo;
|
@@ -797,14 +799,14 @@ case 4:
|
|
797
799
|
}
|
798
800
|
|
799
801
|
|
800
|
-
#line
|
802
|
+
#line 803 "parser.c"
|
801
803
|
static const int JSON_float_start = 1;
|
802
804
|
static const int JSON_float_first_final = 10;
|
803
805
|
static const int JSON_float_error = 0;
|
804
806
|
|
805
807
|
static const int JSON_float_en_main = 1;
|
806
808
|
|
807
|
-
#line
|
809
|
+
#line 267 "parser.rl"
|
808
810
|
|
809
811
|
|
810
812
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -812,14 +814,14 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
812
814
|
int cs = EVIL;
|
813
815
|
|
814
816
|
|
815
|
-
#line
|
817
|
+
#line 818 "parser.c"
|
816
818
|
{
|
817
819
|
cs = JSON_float_start;
|
818
820
|
}
|
819
|
-
#line
|
821
|
+
#line 274 "parser.rl"
|
820
822
|
json->memo = p;
|
821
823
|
|
822
|
-
#line
|
824
|
+
#line 825 "parser.c"
|
823
825
|
{
|
824
826
|
if ( p == pe )
|
825
827
|
goto _out;
|
@@ -876,14 +878,14 @@ case 5:
|
|
876
878
|
goto st0;
|
877
879
|
goto tr7;
|
878
880
|
tr7:
|
879
|
-
#line
|
881
|
+
#line 261 "parser.rl"
|
880
882
|
{ goto _out10; }
|
881
883
|
goto st10;
|
882
884
|
st10:
|
883
885
|
if ( ++p == pe )
|
884
886
|
goto _out10;
|
885
887
|
case 10:
|
886
|
-
#line
|
888
|
+
#line 889 "parser.c"
|
887
889
|
goto st0;
|
888
890
|
st6:
|
889
891
|
if ( ++p == pe )
|
@@ -943,7 +945,7 @@ case 9:
|
|
943
945
|
|
944
946
|
_out: {}
|
945
947
|
}
|
946
|
-
#line
|
948
|
+
#line 276 "parser.rl"
|
947
949
|
|
948
950
|
if (cs >= JSON_float_first_final) {
|
949
951
|
long len = p - json->memo;
|
@@ -956,14 +958,14 @@ case 9:
|
|
956
958
|
|
957
959
|
|
958
960
|
|
959
|
-
#line
|
961
|
+
#line 962 "parser.c"
|
960
962
|
static const int JSON_array_start = 1;
|
961
963
|
static const int JSON_array_first_final = 17;
|
962
964
|
static const int JSON_array_error = 0;
|
963
965
|
|
964
966
|
static const int JSON_array_en_main = 1;
|
965
967
|
|
966
|
-
#line
|
968
|
+
#line 312 "parser.rl"
|
967
969
|
|
968
970
|
|
969
971
|
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -976,13 +978,13 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
976
978
|
*result = rb_ary_new();
|
977
979
|
|
978
980
|
|
979
|
-
#line
|
981
|
+
#line 982 "parser.c"
|
980
982
|
{
|
981
983
|
cs = JSON_array_start;
|
982
984
|
}
|
983
|
-
#line
|
985
|
+
#line 324 "parser.rl"
|
984
986
|
|
985
|
-
#line
|
987
|
+
#line 988 "parser.c"
|
986
988
|
{
|
987
989
|
if ( p == pe )
|
988
990
|
goto _out;
|
@@ -1020,7 +1022,7 @@ case 2:
|
|
1020
1022
|
goto st2;
|
1021
1023
|
goto st0;
|
1022
1024
|
tr2:
|
1023
|
-
#line
|
1025
|
+
#line 293 "parser.rl"
|
1024
1026
|
{
|
1025
1027
|
VALUE v = Qnil;
|
1026
1028
|
char *np = JSON_parse_value(json, p, pe, &v);
|
@@ -1036,7 +1038,7 @@ st3:
|
|
1036
1038
|
if ( ++p == pe )
|
1037
1039
|
goto _out3;
|
1038
1040
|
case 3:
|
1039
|
-
#line
|
1041
|
+
#line 1042 "parser.c"
|
1040
1042
|
switch( (*p) ) {
|
1041
1043
|
case 13: goto st3;
|
1042
1044
|
case 32: goto st3;
|
@@ -1136,14 +1138,14 @@ case 12:
|
|
1136
1138
|
goto st3;
|
1137
1139
|
goto st12;
|
1138
1140
|
tr4:
|
1139
|
-
#line
|
1141
|
+
#line 304 "parser.rl"
|
1140
1142
|
{ goto _out17; }
|
1141
1143
|
goto st17;
|
1142
1144
|
st17:
|
1143
1145
|
if ( ++p == pe )
|
1144
1146
|
goto _out17;
|
1145
1147
|
case 17:
|
1146
|
-
#line
|
1148
|
+
#line 1149 "parser.c"
|
1147
1149
|
goto st0;
|
1148
1150
|
st13:
|
1149
1151
|
if ( ++p == pe )
|
@@ -1198,7 +1200,7 @@ case 16:
|
|
1198
1200
|
|
1199
1201
|
_out: {}
|
1200
1202
|
}
|
1201
|
-
#line
|
1203
|
+
#line 325 "parser.rl"
|
1202
1204
|
|
1203
1205
|
if(cs >= JSON_array_first_final) {
|
1204
1206
|
return p + 1;
|
@@ -1264,14 +1266,14 @@ static VALUE json_string_unescape(char *p, char *pe)
|
|
1264
1266
|
}
|
1265
1267
|
|
1266
1268
|
|
1267
|
-
#line
|
1269
|
+
#line 1270 "parser.c"
|
1268
1270
|
static const int JSON_string_start = 1;
|
1269
1271
|
static const int JSON_string_first_final = 8;
|
1270
1272
|
static const int JSON_string_error = 0;
|
1271
1273
|
|
1272
1274
|
static const int JSON_string_en_main = 1;
|
1273
1275
|
|
1274
|
-
#line
|
1276
|
+
#line 403 "parser.rl"
|
1275
1277
|
|
1276
1278
|
|
1277
1279
|
static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -1280,14 +1282,14 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
1280
1282
|
|
1281
1283
|
*result = rb_str_new("", 0);
|
1282
1284
|
|
1283
|
-
#line
|
1285
|
+
#line 1286 "parser.c"
|
1284
1286
|
{
|
1285
1287
|
cs = JSON_string_start;
|
1286
1288
|
}
|
1287
|
-
#line
|
1289
|
+
#line 411 "parser.rl"
|
1288
1290
|
json->memo = p;
|
1289
1291
|
|
1290
|
-
#line
|
1292
|
+
#line 1293 "parser.c"
|
1291
1293
|
{
|
1292
1294
|
if ( p == pe )
|
1293
1295
|
goto _out;
|
@@ -1311,19 +1313,19 @@ case 2:
|
|
1311
1313
|
goto st0;
|
1312
1314
|
goto st2;
|
1313
1315
|
tr2:
|
1314
|
-
#line
|
1316
|
+
#line 395 "parser.rl"
|
1315
1317
|
{
|
1316
1318
|
*result = json_string_unescape(json->memo + 1, p);
|
1317
1319
|
if (NIL_P(*result)) goto _out8; else {p = (( p + 1))-1;}
|
1318
1320
|
}
|
1319
|
-
#line
|
1321
|
+
#line 400 "parser.rl"
|
1320
1322
|
{ goto _out8; }
|
1321
1323
|
goto st8;
|
1322
1324
|
st8:
|
1323
1325
|
if ( ++p == pe )
|
1324
1326
|
goto _out8;
|
1325
1327
|
case 8:
|
1326
|
-
#line
|
1328
|
+
#line 1329 "parser.c"
|
1327
1329
|
goto st0;
|
1328
1330
|
st3:
|
1329
1331
|
if ( ++p == pe )
|
@@ -1398,7 +1400,7 @@ case 7:
|
|
1398
1400
|
|
1399
1401
|
_out: {}
|
1400
1402
|
}
|
1401
|
-
#line
|
1403
|
+
#line 413 "parser.rl"
|
1402
1404
|
|
1403
1405
|
if (cs >= JSON_string_first_final) {
|
1404
1406
|
return p + 1;
|
@@ -1409,14 +1411,14 @@ case 7:
|
|
1409
1411
|
|
1410
1412
|
|
1411
1413
|
|
1412
|
-
#line
|
1414
|
+
#line 1415 "parser.c"
|
1413
1415
|
static const int JSON_start = 1;
|
1414
1416
|
static const int JSON_first_final = 10;
|
1415
1417
|
static const int JSON_error = 0;
|
1416
1418
|
|
1417
1419
|
static const int JSON_en_main = 1;
|
1418
1420
|
|
1419
|
-
#line
|
1421
|
+
#line 447 "parser.rl"
|
1420
1422
|
|
1421
1423
|
|
1422
1424
|
/*
|
@@ -1448,6 +1450,9 @@ static const int JSON_en_main = 1;
|
|
1448
1450
|
* * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
1449
1451
|
* defiance of RFC 4627 to be parsed by the Parser. This option defaults to
|
1450
1452
|
* false.
|
1453
|
+
* * *create_additions*: If set to false, the Parser doesn't create
|
1454
|
+
* additions even if a matchin class and create_id was found. This option
|
1455
|
+
* defaults to true.
|
1451
1456
|
*/
|
1452
1457
|
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
1453
1458
|
{
|
@@ -1462,8 +1467,6 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1462
1467
|
if (len < 2) {
|
1463
1468
|
rb_raise(eParserError, "A JSON text must at least contain two octets!");
|
1464
1469
|
}
|
1465
|
-
json->max_nesting = 19;
|
1466
|
-
json->allow_nan = 0;
|
1467
1470
|
if (!NIL_P(opts)) {
|
1468
1471
|
opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
|
1469
1472
|
if (NIL_P(opts)) {
|
@@ -1478,13 +1481,32 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1478
1481
|
} else {
|
1479
1482
|
json->max_nesting = 0;
|
1480
1483
|
}
|
1484
|
+
} else {
|
1485
|
+
json->max_nesting = 19;
|
1481
1486
|
}
|
1482
1487
|
tmp = ID2SYM(i_allow_nan);
|
1483
1488
|
if (st_lookup(RHASH(opts)->tbl, tmp, 0)) {
|
1484
1489
|
VALUE allow_nan = rb_hash_aref(opts, tmp);
|
1485
|
-
|
1490
|
+
json->allow_nan = RTEST(allow_nan) ? 1 : 0;
|
1491
|
+
} else {
|
1492
|
+
json->allow_nan = 0;
|
1493
|
+
}
|
1494
|
+
tmp = ID2SYM(i_create_additions);
|
1495
|
+
if (st_lookup(RHASH(opts)->tbl, tmp, 0)) {
|
1496
|
+
VALUE create_additions = rb_hash_aref(opts, tmp);
|
1497
|
+
if (RTEST(create_additions)) {
|
1498
|
+
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
1499
|
+
} else {
|
1500
|
+
json->create_id = Qnil;
|
1501
|
+
}
|
1502
|
+
} else {
|
1503
|
+
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
1486
1504
|
}
|
1487
1505
|
}
|
1506
|
+
} else {
|
1507
|
+
json->max_nesting = 19;
|
1508
|
+
json->allow_nan = 0;
|
1509
|
+
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
1488
1510
|
}
|
1489
1511
|
json->current_nesting = 0;
|
1490
1512
|
/*
|
@@ -1502,7 +1524,6 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1502
1524
|
json->len = len;
|
1503
1525
|
json->source = ptr;
|
1504
1526
|
json->Vsource = source;
|
1505
|
-
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
1506
1527
|
return self;
|
1507
1528
|
}
|
1508
1529
|
|
@@ -1520,15 +1541,15 @@ static VALUE cParser_parse(VALUE self)
|
|
1520
1541
|
GET_STRUCT;
|
1521
1542
|
|
1522
1543
|
|
1523
|
-
#line
|
1544
|
+
#line 1545 "parser.c"
|
1524
1545
|
{
|
1525
1546
|
cs = JSON_start;
|
1526
1547
|
}
|
1527
|
-
#line
|
1548
|
+
#line 569 "parser.rl"
|
1528
1549
|
p = json->source;
|
1529
1550
|
pe = p + json->len;
|
1530
1551
|
|
1531
|
-
#line
|
1552
|
+
#line 1553 "parser.c"
|
1532
1553
|
{
|
1533
1554
|
if ( p == pe )
|
1534
1555
|
goto _out;
|
@@ -1583,7 +1604,7 @@ case 5:
|
|
1583
1604
|
goto st1;
|
1584
1605
|
goto st5;
|
1585
1606
|
tr3:
|
1586
|
-
#line
|
1607
|
+
#line 436 "parser.rl"
|
1587
1608
|
{
|
1588
1609
|
char *np;
|
1589
1610
|
json->current_nesting = 1;
|
@@ -1592,7 +1613,7 @@ tr3:
|
|
1592
1613
|
}
|
1593
1614
|
goto st10;
|
1594
1615
|
tr4:
|
1595
|
-
#line
|
1616
|
+
#line 429 "parser.rl"
|
1596
1617
|
{
|
1597
1618
|
char *np;
|
1598
1619
|
json->current_nesting = 1;
|
@@ -1604,7 +1625,7 @@ st10:
|
|
1604
1625
|
if ( ++p == pe )
|
1605
1626
|
goto _out10;
|
1606
1627
|
case 10:
|
1607
|
-
#line
|
1628
|
+
#line 1629 "parser.c"
|
1608
1629
|
switch( (*p) ) {
|
1609
1630
|
case 13: goto st10;
|
1610
1631
|
case 32: goto st10;
|
@@ -1660,7 +1681,7 @@ case 9:
|
|
1660
1681
|
|
1661
1682
|
_out: {}
|
1662
1683
|
}
|
1663
|
-
#line
|
1684
|
+
#line 572 "parser.rl"
|
1664
1685
|
|
1665
1686
|
if (cs >= JSON_first_final && p == pe) {
|
1666
1687
|
return result;
|
@@ -1669,7 +1690,7 @@ case 9:
|
|
1669
1690
|
}
|
1670
1691
|
}
|
1671
1692
|
|
1672
|
-
static JSON_Parser *JSON_allocate()
|
1693
|
+
inline static JSON_Parser *JSON_allocate()
|
1673
1694
|
{
|
1674
1695
|
JSON_Parser *json = ALLOC(JSON_Parser);
|
1675
1696
|
MEMZERO(json, JSON_Parser, 1);
|
@@ -1724,6 +1745,7 @@ void Init_parser()
|
|
1724
1745
|
i_json_creatable_p = rb_intern("json_creatable?");
|
1725
1746
|
i_json_create = rb_intern("json_create");
|
1726
1747
|
i_create_id = rb_intern("create_id");
|
1748
|
+
i_create_additions = rb_intern("create_additions");
|
1727
1749
|
i_chr = rb_intern("chr");
|
1728
1750
|
i_max_nesting = rb_intern("max_nesting");
|
1729
1751
|
i_allow_nan = rb_intern("allow_nan");
|