json 1.2.1 → 1.2.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 +4 -1
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +6 -7
- data/ext/json/ext/parser/parser.c +83 -90
- data/ext/json/ext/parser/parser.rl +9 -16
- data/lib/json/version.rb +1 -1
- data/tests/test_json_addition.rb +4 -6
- data/tests/test_json_rails.rb +4 -6
- metadata +2 -2
data/CHANGES
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
2010-02-27 (1.2.2)
|
2
|
+
* Made some changes to make the building of the parser/generator compatible
|
3
|
+
to Rubinius.
|
1
4
|
2009-11-25 (1.2.1)
|
2
|
-
*
|
5
|
+
* Added :symbolize_names option to Parser, which returns symbols instead of
|
3
6
|
strings in object names/keys.
|
4
7
|
2009-10-01 (1.2.0)
|
5
8
|
* fast_generate now raises an exeception for nan and infinite floats.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.2
|
@@ -9,10 +9,6 @@
|
|
9
9
|
#include "unicode.h"
|
10
10
|
#include <math.h>
|
11
11
|
|
12
|
-
#ifndef RHASH_TBL
|
13
|
-
#define RHASH_TBL(hsh) (RHASH(hsh)->tbl)
|
14
|
-
#endif
|
15
|
-
|
16
12
|
#ifndef RHASH_SIZE
|
17
13
|
#define RHASH_SIZE(hsh) (RHASH(hsh)->tbl->num_entries)
|
18
14
|
#endif
|
@@ -21,6 +17,8 @@
|
|
21
17
|
#define RFLOAT_VALUE(val) (RFLOAT(val)->value)
|
22
18
|
#endif
|
23
19
|
|
20
|
+
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
|
21
|
+
|
24
22
|
#ifdef HAVE_RUBY_ENCODING_H
|
25
23
|
#include "ruby/encoding.h"
|
26
24
|
#define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
|
@@ -43,7 +41,7 @@ static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
|
|
43
41
|
|
44
42
|
static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before,
|
45
43
|
i_object_nl, i_array_nl, i_check_circular, i_max_nesting,
|
46
|
-
i_allow_nan, i_pack, i_unpack, i_create_id, i_extend;
|
44
|
+
i_allow_nan, i_pack, i_unpack, i_create_id, i_extend, i_key_p;
|
47
45
|
|
48
46
|
typedef struct JSON_Generator_StateStruct {
|
49
47
|
VALUE indent;
|
@@ -543,7 +541,7 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
543
541
|
state->object_nl = tmp;
|
544
542
|
}
|
545
543
|
tmp = ID2SYM(i_check_circular);
|
546
|
-
if (
|
544
|
+
if (option_given_p(opts, tmp)) {
|
547
545
|
tmp = rb_hash_aref(opts, ID2SYM(i_check_circular));
|
548
546
|
state->check_circular = RTEST(tmp);
|
549
547
|
} else {
|
@@ -551,7 +549,7 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
551
549
|
}
|
552
550
|
tmp = ID2SYM(i_max_nesting);
|
553
551
|
state->max_nesting = 19;
|
554
|
-
if (
|
552
|
+
if (option_given_p(opts, tmp)) {
|
555
553
|
VALUE max_nesting = rb_hash_aref(opts, tmp);
|
556
554
|
if (RTEST(max_nesting)) {
|
557
555
|
Check_Type(max_nesting, T_FIXNUM);
|
@@ -927,6 +925,7 @@ void Init_generator()
|
|
927
925
|
i_unpack = rb_intern("unpack");
|
928
926
|
i_create_id = rb_intern("create_id");
|
929
927
|
i_extend = rb_intern("extend");
|
928
|
+
i_key_p = rb_intern("key?");
|
930
929
|
#ifdef HAVE_RUBY_ENCODING_H
|
931
930
|
mEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
|
932
931
|
i_encoding = rb_intern("encoding");
|
@@ -5,18 +5,10 @@
|
|
5
5
|
#if HAVE_RE_H
|
6
6
|
#include "re.h"
|
7
7
|
#endif
|
8
|
-
#if HAVE_RUBY_ST_H
|
9
|
-
#include "ruby/st.h"
|
10
|
-
#endif
|
11
|
-
#if HAVE_ST_H
|
12
|
-
#include "st.h"
|
13
|
-
#endif
|
14
8
|
|
15
9
|
#define EVIL 0x666
|
16
10
|
|
17
|
-
#
|
18
|
-
#define RHASH_TBL(hsh) (RHASH(hsh)->tbl)
|
19
|
-
#endif
|
11
|
+
#define option_given_p(opts, key) RTEST(rb_funcall((opts), i_key_p, 1, (key)))
|
20
12
|
|
21
13
|
#ifdef HAVE_RUBY_ENCODING_H
|
22
14
|
#include "ruby/encoding.h"
|
@@ -34,7 +26,7 @@ static VALUE CNaN, CInfinity, CMinusInfinity;
|
|
34
26
|
|
35
27
|
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
36
28
|
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_object_class,
|
37
|
-
i_array_class;
|
29
|
+
i_array_class, i_key_p;
|
38
30
|
|
39
31
|
#define MinusInfinity "-Infinity"
|
40
32
|
|
@@ -65,11 +57,11 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
65
57
|
Data_Get_Struct(self, JSON_Parser, json);
|
66
58
|
|
67
59
|
|
68
|
-
#line
|
60
|
+
#line 83 "parser.rl"
|
69
61
|
|
70
62
|
|
71
63
|
|
72
|
-
#line
|
64
|
+
#line 65 "parser.c"
|
73
65
|
static const int JSON_object_start = 1;
|
74
66
|
static const int JSON_object_first_final = 27;
|
75
67
|
static const int JSON_object_error = 0;
|
@@ -77,7 +69,7 @@ static const int JSON_object_error = 0;
|
|
77
69
|
static const int JSON_object_en_main = 1;
|
78
70
|
|
79
71
|
|
80
|
-
#line
|
72
|
+
#line 118 "parser.rl"
|
81
73
|
|
82
74
|
|
83
75
|
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -93,14 +85,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
93
85
|
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
|
94
86
|
|
95
87
|
|
96
|
-
#line
|
88
|
+
#line 89 "parser.c"
|
97
89
|
{
|
98
90
|
cs = JSON_object_start;
|
99
91
|
}
|
100
92
|
|
101
|
-
#line
|
93
|
+
#line 133 "parser.rl"
|
102
94
|
|
103
|
-
#line
|
95
|
+
#line 96 "parser.c"
|
104
96
|
{
|
105
97
|
if ( p == pe )
|
106
98
|
goto _test_eof;
|
@@ -128,7 +120,7 @@ case 2:
|
|
128
120
|
goto st2;
|
129
121
|
goto st0;
|
130
122
|
tr2:
|
131
|
-
#line
|
123
|
+
#line 102 "parser.rl"
|
132
124
|
{
|
133
125
|
json->parsing_name = 1;
|
134
126
|
char *np = JSON_parse_string(json, p, pe, &last_name);
|
@@ -140,7 +132,7 @@ st3:
|
|
140
132
|
if ( ++p == pe )
|
141
133
|
goto _test_eof3;
|
142
134
|
case 3:
|
143
|
-
#line
|
135
|
+
#line 136 "parser.c"
|
144
136
|
switch( (*p) ) {
|
145
137
|
case 13: goto st3;
|
146
138
|
case 32: goto st3;
|
@@ -207,7 +199,7 @@ case 8:
|
|
207
199
|
goto st8;
|
208
200
|
goto st0;
|
209
201
|
tr11:
|
210
|
-
#line
|
202
|
+
#line 91 "parser.rl"
|
211
203
|
{
|
212
204
|
VALUE v = Qnil;
|
213
205
|
char *np = JSON_parse_value(json, p, pe, &v);
|
@@ -223,7 +215,7 @@ st9:
|
|
223
215
|
if ( ++p == pe )
|
224
216
|
goto _test_eof9;
|
225
217
|
case 9:
|
226
|
-
#line
|
218
|
+
#line 219 "parser.c"
|
227
219
|
switch( (*p) ) {
|
228
220
|
case 13: goto st9;
|
229
221
|
case 32: goto st9;
|
@@ -312,14 +304,14 @@ case 18:
|
|
312
304
|
goto st9;
|
313
305
|
goto st18;
|
314
306
|
tr4:
|
315
|
-
#line
|
307
|
+
#line 109 "parser.rl"
|
316
308
|
{ p--; {p++; cs = 27; goto _out;} }
|
317
309
|
goto st27;
|
318
310
|
st27:
|
319
311
|
if ( ++p == pe )
|
320
312
|
goto _test_eof27;
|
321
313
|
case 27:
|
322
|
-
#line
|
314
|
+
#line 315 "parser.c"
|
323
315
|
goto st0;
|
324
316
|
st19:
|
325
317
|
if ( ++p == pe )
|
@@ -417,7 +409,7 @@ case 26:
|
|
417
409
|
_out: {}
|
418
410
|
}
|
419
411
|
|
420
|
-
#line
|
412
|
+
#line 134 "parser.rl"
|
421
413
|
|
422
414
|
if (cs >= JSON_object_first_final) {
|
423
415
|
if (RTEST(json->create_id)) {
|
@@ -436,7 +428,7 @@ case 26:
|
|
436
428
|
}
|
437
429
|
|
438
430
|
|
439
|
-
#line
|
431
|
+
#line 432 "parser.c"
|
440
432
|
static const int JSON_value_start = 1;
|
441
433
|
static const int JSON_value_first_final = 21;
|
442
434
|
static const int JSON_value_error = 0;
|
@@ -444,7 +436,7 @@ static const int JSON_value_error = 0;
|
|
444
436
|
static const int JSON_value_en_main = 1;
|
445
437
|
|
446
438
|
|
447
|
-
#line
|
439
|
+
#line 232 "parser.rl"
|
448
440
|
|
449
441
|
|
450
442
|
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -452,14 +444,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
452
444
|
int cs = EVIL;
|
453
445
|
|
454
446
|
|
455
|
-
#line
|
447
|
+
#line 448 "parser.c"
|
456
448
|
{
|
457
449
|
cs = JSON_value_start;
|
458
450
|
}
|
459
451
|
|
460
|
-
#line
|
452
|
+
#line 239 "parser.rl"
|
461
453
|
|
462
|
-
#line
|
454
|
+
#line 455 "parser.c"
|
463
455
|
{
|
464
456
|
if ( p == pe )
|
465
457
|
goto _test_eof;
|
@@ -484,14 +476,14 @@ st0:
|
|
484
476
|
cs = 0;
|
485
477
|
goto _out;
|
486
478
|
tr0:
|
487
|
-
#line
|
479
|
+
#line 180 "parser.rl"
|
488
480
|
{
|
489
481
|
char *np = JSON_parse_string(json, p, pe, result);
|
490
482
|
if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
|
491
483
|
}
|
492
484
|
goto st21;
|
493
485
|
tr2:
|
494
|
-
#line
|
486
|
+
#line 185 "parser.rl"
|
495
487
|
{
|
496
488
|
char *np;
|
497
489
|
if(pe > p + 9 && !strncmp(MinusInfinity, p, 9)) {
|
@@ -511,7 +503,7 @@ tr2:
|
|
511
503
|
}
|
512
504
|
goto st21;
|
513
505
|
tr5:
|
514
|
-
#line
|
506
|
+
#line 203 "parser.rl"
|
515
507
|
{
|
516
508
|
char *np;
|
517
509
|
json->current_nesting++;
|
@@ -521,7 +513,7 @@ tr5:
|
|
521
513
|
}
|
522
514
|
goto st21;
|
523
515
|
tr9:
|
524
|
-
#line
|
516
|
+
#line 211 "parser.rl"
|
525
517
|
{
|
526
518
|
char *np;
|
527
519
|
json->current_nesting++;
|
@@ -531,7 +523,7 @@ tr9:
|
|
531
523
|
}
|
532
524
|
goto st21;
|
533
525
|
tr16:
|
534
|
-
#line
|
526
|
+
#line 173 "parser.rl"
|
535
527
|
{
|
536
528
|
if (json->allow_nan) {
|
537
529
|
*result = CInfinity;
|
@@ -541,7 +533,7 @@ tr16:
|
|
541
533
|
}
|
542
534
|
goto st21;
|
543
535
|
tr18:
|
544
|
-
#line
|
536
|
+
#line 166 "parser.rl"
|
545
537
|
{
|
546
538
|
if (json->allow_nan) {
|
547
539
|
*result = CNaN;
|
@@ -551,19 +543,19 @@ tr18:
|
|
551
543
|
}
|
552
544
|
goto st21;
|
553
545
|
tr22:
|
554
|
-
#line
|
546
|
+
#line 160 "parser.rl"
|
555
547
|
{
|
556
548
|
*result = Qfalse;
|
557
549
|
}
|
558
550
|
goto st21;
|
559
551
|
tr25:
|
560
|
-
#line
|
552
|
+
#line 157 "parser.rl"
|
561
553
|
{
|
562
554
|
*result = Qnil;
|
563
555
|
}
|
564
556
|
goto st21;
|
565
557
|
tr28:
|
566
|
-
#line
|
558
|
+
#line 163 "parser.rl"
|
567
559
|
{
|
568
560
|
*result = Qtrue;
|
569
561
|
}
|
@@ -572,9 +564,9 @@ st21:
|
|
572
564
|
if ( ++p == pe )
|
573
565
|
goto _test_eof21;
|
574
566
|
case 21:
|
575
|
-
#line
|
567
|
+
#line 219 "parser.rl"
|
576
568
|
{ p--; {p++; cs = 21; goto _out;} }
|
577
|
-
#line
|
569
|
+
#line 570 "parser.c"
|
578
570
|
goto st0;
|
579
571
|
st2:
|
580
572
|
if ( ++p == pe )
|
@@ -735,7 +727,7 @@ case 20:
|
|
735
727
|
_out: {}
|
736
728
|
}
|
737
729
|
|
738
|
-
#line
|
730
|
+
#line 240 "parser.rl"
|
739
731
|
|
740
732
|
if (cs >= JSON_value_first_final) {
|
741
733
|
return p;
|
@@ -745,7 +737,7 @@ case 20:
|
|
745
737
|
}
|
746
738
|
|
747
739
|
|
748
|
-
#line
|
740
|
+
#line 741 "parser.c"
|
749
741
|
static const int JSON_integer_start = 1;
|
750
742
|
static const int JSON_integer_first_final = 5;
|
751
743
|
static const int JSON_integer_error = 0;
|
@@ -753,7 +745,7 @@ static const int JSON_integer_error = 0;
|
|
753
745
|
static const int JSON_integer_en_main = 1;
|
754
746
|
|
755
747
|
|
756
|
-
#line
|
748
|
+
#line 256 "parser.rl"
|
757
749
|
|
758
750
|
|
759
751
|
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -761,15 +753,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
761
753
|
int cs = EVIL;
|
762
754
|
|
763
755
|
|
764
|
-
#line
|
756
|
+
#line 757 "parser.c"
|
765
757
|
{
|
766
758
|
cs = JSON_integer_start;
|
767
759
|
}
|
768
760
|
|
769
|
-
#line
|
761
|
+
#line 263 "parser.rl"
|
770
762
|
json->memo = p;
|
771
763
|
|
772
|
-
#line
|
764
|
+
#line 765 "parser.c"
|
773
765
|
{
|
774
766
|
if ( p == pe )
|
775
767
|
goto _test_eof;
|
@@ -803,14 +795,14 @@ case 3:
|
|
803
795
|
goto st0;
|
804
796
|
goto tr4;
|
805
797
|
tr4:
|
806
|
-
#line
|
798
|
+
#line 253 "parser.rl"
|
807
799
|
{ p--; {p++; cs = 5; goto _out;} }
|
808
800
|
goto st5;
|
809
801
|
st5:
|
810
802
|
if ( ++p == pe )
|
811
803
|
goto _test_eof5;
|
812
804
|
case 5:
|
813
|
-
#line
|
805
|
+
#line 806 "parser.c"
|
814
806
|
goto st0;
|
815
807
|
st4:
|
816
808
|
if ( ++p == pe )
|
@@ -829,7 +821,7 @@ case 4:
|
|
829
821
|
_out: {}
|
830
822
|
}
|
831
823
|
|
832
|
-
#line
|
824
|
+
#line 265 "parser.rl"
|
833
825
|
|
834
826
|
if (cs >= JSON_integer_first_final) {
|
835
827
|
long len = p - json->memo;
|
@@ -841,7 +833,7 @@ case 4:
|
|
841
833
|
}
|
842
834
|
|
843
835
|
|
844
|
-
#line
|
836
|
+
#line 837 "parser.c"
|
845
837
|
static const int JSON_float_start = 1;
|
846
838
|
static const int JSON_float_first_final = 10;
|
847
839
|
static const int JSON_float_error = 0;
|
@@ -849,7 +841,7 @@ static const int JSON_float_error = 0;
|
|
849
841
|
static const int JSON_float_en_main = 1;
|
850
842
|
|
851
843
|
|
852
|
-
#line
|
844
|
+
#line 287 "parser.rl"
|
853
845
|
|
854
846
|
|
855
847
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -857,15 +849,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
857
849
|
int cs = EVIL;
|
858
850
|
|
859
851
|
|
860
|
-
#line
|
852
|
+
#line 853 "parser.c"
|
861
853
|
{
|
862
854
|
cs = JSON_float_start;
|
863
855
|
}
|
864
856
|
|
865
|
-
#line
|
857
|
+
#line 294 "parser.rl"
|
866
858
|
json->memo = p;
|
867
859
|
|
868
|
-
#line
|
860
|
+
#line 861 "parser.c"
|
869
861
|
{
|
870
862
|
if ( p == pe )
|
871
863
|
goto _test_eof;
|
@@ -923,14 +915,14 @@ case 5:
|
|
923
915
|
goto st0;
|
924
916
|
goto tr7;
|
925
917
|
tr7:
|
926
|
-
#line
|
918
|
+
#line 281 "parser.rl"
|
927
919
|
{ p--; {p++; cs = 10; goto _out;} }
|
928
920
|
goto st10;
|
929
921
|
st10:
|
930
922
|
if ( ++p == pe )
|
931
923
|
goto _test_eof10;
|
932
924
|
case 10:
|
933
|
-
#line
|
925
|
+
#line 926 "parser.c"
|
934
926
|
goto st0;
|
935
927
|
st6:
|
936
928
|
if ( ++p == pe )
|
@@ -991,7 +983,7 @@ case 9:
|
|
991
983
|
_out: {}
|
992
984
|
}
|
993
985
|
|
994
|
-
#line
|
986
|
+
#line 296 "parser.rl"
|
995
987
|
|
996
988
|
if (cs >= JSON_float_first_final) {
|
997
989
|
long len = p - json->memo;
|
@@ -1004,7 +996,7 @@ case 9:
|
|
1004
996
|
|
1005
997
|
|
1006
998
|
|
1007
|
-
#line
|
999
|
+
#line 1000 "parser.c"
|
1008
1000
|
static const int JSON_array_start = 1;
|
1009
1001
|
static const int JSON_array_first_final = 17;
|
1010
1002
|
static const int JSON_array_error = 0;
|
@@ -1012,7 +1004,7 @@ static const int JSON_array_error = 0;
|
|
1012
1004
|
static const int JSON_array_en_main = 1;
|
1013
1005
|
|
1014
1006
|
|
1015
|
-
#line
|
1007
|
+
#line 332 "parser.rl"
|
1016
1008
|
|
1017
1009
|
|
1018
1010
|
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -1026,14 +1018,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
1026
1018
|
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
|
1027
1019
|
|
1028
1020
|
|
1029
|
-
#line
|
1021
|
+
#line 1022 "parser.c"
|
1030
1022
|
{
|
1031
1023
|
cs = JSON_array_start;
|
1032
1024
|
}
|
1033
1025
|
|
1034
|
-
#line
|
1026
|
+
#line 345 "parser.rl"
|
1035
1027
|
|
1036
|
-
#line
|
1028
|
+
#line 1029 "parser.c"
|
1037
1029
|
{
|
1038
1030
|
if ( p == pe )
|
1039
1031
|
goto _test_eof;
|
@@ -1072,7 +1064,7 @@ case 2:
|
|
1072
1064
|
goto st2;
|
1073
1065
|
goto st0;
|
1074
1066
|
tr2:
|
1075
|
-
#line
|
1067
|
+
#line 313 "parser.rl"
|
1076
1068
|
{
|
1077
1069
|
VALUE v = Qnil;
|
1078
1070
|
char *np = JSON_parse_value(json, p, pe, &v);
|
@@ -1088,7 +1080,7 @@ st3:
|
|
1088
1080
|
if ( ++p == pe )
|
1089
1081
|
goto _test_eof3;
|
1090
1082
|
case 3:
|
1091
|
-
#line
|
1083
|
+
#line 1084 "parser.c"
|
1092
1084
|
switch( (*p) ) {
|
1093
1085
|
case 13: goto st3;
|
1094
1086
|
case 32: goto st3;
|
@@ -1188,14 +1180,14 @@ case 12:
|
|
1188
1180
|
goto st3;
|
1189
1181
|
goto st12;
|
1190
1182
|
tr4:
|
1191
|
-
#line
|
1183
|
+
#line 324 "parser.rl"
|
1192
1184
|
{ p--; {p++; cs = 17; goto _out;} }
|
1193
1185
|
goto st17;
|
1194
1186
|
st17:
|
1195
1187
|
if ( ++p == pe )
|
1196
1188
|
goto _test_eof17;
|
1197
1189
|
case 17:
|
1198
|
-
#line
|
1190
|
+
#line 1191 "parser.c"
|
1199
1191
|
goto st0;
|
1200
1192
|
st13:
|
1201
1193
|
if ( ++p == pe )
|
@@ -1251,7 +1243,7 @@ case 16:
|
|
1251
1243
|
_out: {}
|
1252
1244
|
}
|
1253
1245
|
|
1254
|
-
#line
|
1246
|
+
#line 346 "parser.rl"
|
1255
1247
|
|
1256
1248
|
if(cs >= JSON_array_first_final) {
|
1257
1249
|
return p + 1;
|
@@ -1317,7 +1309,7 @@ static VALUE json_string_unescape(char *p, char *pe)
|
|
1317
1309
|
}
|
1318
1310
|
|
1319
1311
|
|
1320
|
-
#line
|
1312
|
+
#line 1313 "parser.c"
|
1321
1313
|
static const int JSON_string_start = 1;
|
1322
1314
|
static const int JSON_string_first_final = 8;
|
1323
1315
|
static const int JSON_string_error = 0;
|
@@ -1325,7 +1317,7 @@ static const int JSON_string_error = 0;
|
|
1325
1317
|
static const int JSON_string_en_main = 1;
|
1326
1318
|
|
1327
1319
|
|
1328
|
-
#line
|
1320
|
+
#line 430 "parser.rl"
|
1329
1321
|
|
1330
1322
|
|
1331
1323
|
static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
@@ -1334,15 +1326,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
1334
1326
|
|
1335
1327
|
*result = rb_str_new("", 0);
|
1336
1328
|
|
1337
|
-
#line
|
1329
|
+
#line 1330 "parser.c"
|
1338
1330
|
{
|
1339
1331
|
cs = JSON_string_start;
|
1340
1332
|
}
|
1341
1333
|
|
1342
|
-
#line
|
1334
|
+
#line 438 "parser.rl"
|
1343
1335
|
json->memo = p;
|
1344
1336
|
|
1345
|
-
#line
|
1337
|
+
#line 1338 "parser.c"
|
1346
1338
|
{
|
1347
1339
|
if ( p == pe )
|
1348
1340
|
goto _test_eof;
|
@@ -1367,7 +1359,7 @@ case 2:
|
|
1367
1359
|
goto st0;
|
1368
1360
|
goto st2;
|
1369
1361
|
tr2:
|
1370
|
-
#line
|
1362
|
+
#line 416 "parser.rl"
|
1371
1363
|
{
|
1372
1364
|
*result = json_string_unescape(json->memo + 1, p);
|
1373
1365
|
if (NIL_P(*result)) {
|
@@ -1378,14 +1370,14 @@ tr2:
|
|
1378
1370
|
{p = (( p + 1))-1;}
|
1379
1371
|
}
|
1380
1372
|
}
|
1381
|
-
#line
|
1373
|
+
#line 427 "parser.rl"
|
1382
1374
|
{ p--; {p++; cs = 8; goto _out;} }
|
1383
1375
|
goto st8;
|
1384
1376
|
st8:
|
1385
1377
|
if ( ++p == pe )
|
1386
1378
|
goto _test_eof8;
|
1387
1379
|
case 8:
|
1388
|
-
#line
|
1380
|
+
#line 1381 "parser.c"
|
1389
1381
|
goto st0;
|
1390
1382
|
st3:
|
1391
1383
|
if ( ++p == pe )
|
@@ -1461,7 +1453,7 @@ case 7:
|
|
1461
1453
|
_out: {}
|
1462
1454
|
}
|
1463
1455
|
|
1464
|
-
#line
|
1456
|
+
#line 440 "parser.rl"
|
1465
1457
|
|
1466
1458
|
if (json->symbolize_names && json->parsing_name) {
|
1467
1459
|
*result = rb_str_intern(*result);
|
@@ -1475,7 +1467,7 @@ case 7:
|
|
1475
1467
|
|
1476
1468
|
|
1477
1469
|
|
1478
|
-
#line
|
1470
|
+
#line 1471 "parser.c"
|
1479
1471
|
static const int JSON_start = 1;
|
1480
1472
|
static const int JSON_first_final = 10;
|
1481
1473
|
static const int JSON_error = 0;
|
@@ -1483,7 +1475,7 @@ static const int JSON_error = 0;
|
|
1483
1475
|
static const int JSON_en_main = 1;
|
1484
1476
|
|
1485
1477
|
|
1486
|
-
#line
|
1478
|
+
#line 477 "parser.rl"
|
1487
1479
|
|
1488
1480
|
|
1489
1481
|
/*
|
@@ -1588,7 +1580,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1588
1580
|
rb_raise(rb_eArgError, "opts needs to be like a hash");
|
1589
1581
|
} else {
|
1590
1582
|
VALUE tmp = ID2SYM(i_max_nesting);
|
1591
|
-
if (
|
1583
|
+
if (option_given_p(opts, tmp)) {
|
1592
1584
|
VALUE max_nesting = rb_hash_aref(opts, tmp);
|
1593
1585
|
if (RTEST(max_nesting)) {
|
1594
1586
|
Check_Type(max_nesting, T_FIXNUM);
|
@@ -1600,21 +1592,21 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1600
1592
|
json->max_nesting = 19;
|
1601
1593
|
}
|
1602
1594
|
tmp = ID2SYM(i_allow_nan);
|
1603
|
-
if (
|
1595
|
+
if (option_given_p(opts, tmp)) {
|
1604
1596
|
VALUE allow_nan = rb_hash_aref(opts, tmp);
|
1605
1597
|
json->allow_nan = RTEST(allow_nan) ? 1 : 0;
|
1606
1598
|
} else {
|
1607
1599
|
json->allow_nan = 0;
|
1608
1600
|
}
|
1609
1601
|
tmp = ID2SYM(i_symbolize_names);
|
1610
|
-
if (
|
1602
|
+
if (option_given_p(opts, tmp)) {
|
1611
1603
|
VALUE symbolize_names = rb_hash_aref(opts, tmp);
|
1612
1604
|
json->symbolize_names = RTEST(symbolize_names) ? 1 : 0;
|
1613
1605
|
} else {
|
1614
1606
|
json->symbolize_names = 0;
|
1615
1607
|
}
|
1616
1608
|
tmp = ID2SYM(i_create_additions);
|
1617
|
-
if (
|
1609
|
+
if (option_given_p(opts, tmp)) {
|
1618
1610
|
VALUE create_additions = rb_hash_aref(opts, tmp);
|
1619
1611
|
if (RTEST(create_additions)) {
|
1620
1612
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
@@ -1625,13 +1617,13 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1625
1617
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
1626
1618
|
}
|
1627
1619
|
tmp = ID2SYM(i_object_class);
|
1628
|
-
if (
|
1620
|
+
if (option_given_p(opts, tmp)) {
|
1629
1621
|
json->object_class = rb_hash_aref(opts, tmp);
|
1630
1622
|
} else {
|
1631
1623
|
json->object_class = Qnil;
|
1632
1624
|
}
|
1633
1625
|
tmp = ID2SYM(i_array_class);
|
1634
|
-
if (
|
1626
|
+
if (option_given_p(opts, tmp)) {
|
1635
1627
|
json->array_class = rb_hash_aref(opts, tmp);
|
1636
1628
|
} else {
|
1637
1629
|
json->array_class = Qnil;
|
@@ -1665,16 +1657,16 @@ static VALUE cParser_parse(VALUE self)
|
|
1665
1657
|
GET_STRUCT;
|
1666
1658
|
|
1667
1659
|
|
1668
|
-
#line
|
1660
|
+
#line 1661 "parser.c"
|
1669
1661
|
{
|
1670
1662
|
cs = JSON_start;
|
1671
1663
|
}
|
1672
1664
|
|
1673
|
-
#line
|
1665
|
+
#line 658 "parser.rl"
|
1674
1666
|
p = json->source;
|
1675
1667
|
pe = p + json->len;
|
1676
1668
|
|
1677
|
-
#line
|
1669
|
+
#line 1670 "parser.c"
|
1678
1670
|
{
|
1679
1671
|
if ( p == pe )
|
1680
1672
|
goto _test_eof;
|
@@ -1730,7 +1722,7 @@ case 5:
|
|
1730
1722
|
goto st1;
|
1731
1723
|
goto st5;
|
1732
1724
|
tr3:
|
1733
|
-
#line
|
1725
|
+
#line 466 "parser.rl"
|
1734
1726
|
{
|
1735
1727
|
char *np;
|
1736
1728
|
json->current_nesting = 1;
|
@@ -1739,7 +1731,7 @@ tr3:
|
|
1739
1731
|
}
|
1740
1732
|
goto st10;
|
1741
1733
|
tr4:
|
1742
|
-
#line
|
1734
|
+
#line 459 "parser.rl"
|
1743
1735
|
{
|
1744
1736
|
char *np;
|
1745
1737
|
json->current_nesting = 1;
|
@@ -1751,7 +1743,7 @@ st10:
|
|
1751
1743
|
if ( ++p == pe )
|
1752
1744
|
goto _test_eof10;
|
1753
1745
|
case 10:
|
1754
|
-
#line
|
1746
|
+
#line 1747 "parser.c"
|
1755
1747
|
switch( (*p) ) {
|
1756
1748
|
case 13: goto st10;
|
1757
1749
|
case 32: goto st10;
|
@@ -1808,7 +1800,7 @@ case 9:
|
|
1808
1800
|
_out: {}
|
1809
1801
|
}
|
1810
1802
|
|
1811
|
-
#line
|
1803
|
+
#line 661 "parser.rl"
|
1812
1804
|
|
1813
1805
|
if (cs >= JSON_first_final && p == pe) {
|
1814
1806
|
return result;
|
@@ -1882,6 +1874,7 @@ void Init_parser()
|
|
1882
1874
|
i_symbolize_names = rb_intern("symbolize_names");
|
1883
1875
|
i_object_class = rb_intern("object_class");
|
1884
1876
|
i_array_class = rb_intern("array_class");
|
1877
|
+
i_key_p = rb_intern("key?");
|
1885
1878
|
#ifdef HAVE_RUBY_ENCODING_H
|
1886
1879
|
mEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
|
1887
1880
|
mEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
|
@@ -3,18 +3,10 @@
|
|
3
3
|
#if HAVE_RE_H
|
4
4
|
#include "re.h"
|
5
5
|
#endif
|
6
|
-
#if HAVE_RUBY_ST_H
|
7
|
-
#include "ruby/st.h"
|
8
|
-
#endif
|
9
|
-
#if HAVE_ST_H
|
10
|
-
#include "st.h"
|
11
|
-
#endif
|
12
6
|
|
13
7
|
#define EVIL 0x666
|
14
8
|
|
15
|
-
#
|
16
|
-
#define RHASH_TBL(hsh) (RHASH(hsh)->tbl)
|
17
|
-
#endif
|
9
|
+
#define option_given_p(opts, key) RTEST(rb_funcall((opts), i_key_p, 1, (key)))
|
18
10
|
|
19
11
|
#ifdef HAVE_RUBY_ENCODING_H
|
20
12
|
#include "ruby/encoding.h"
|
@@ -32,7 +24,7 @@ static VALUE CNaN, CInfinity, CMinusInfinity;
|
|
32
24
|
|
33
25
|
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
34
26
|
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_object_class,
|
35
|
-
i_array_class;
|
27
|
+
i_array_class, i_key_p;
|
36
28
|
|
37
29
|
#define MinusInfinity "-Infinity"
|
38
30
|
|
@@ -586,7 +578,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
586
578
|
rb_raise(rb_eArgError, "opts needs to be like a hash");
|
587
579
|
} else {
|
588
580
|
VALUE tmp = ID2SYM(i_max_nesting);
|
589
|
-
if (
|
581
|
+
if (option_given_p(opts, tmp)) {
|
590
582
|
VALUE max_nesting = rb_hash_aref(opts, tmp);
|
591
583
|
if (RTEST(max_nesting)) {
|
592
584
|
Check_Type(max_nesting, T_FIXNUM);
|
@@ -598,21 +590,21 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
598
590
|
json->max_nesting = 19;
|
599
591
|
}
|
600
592
|
tmp = ID2SYM(i_allow_nan);
|
601
|
-
if (
|
593
|
+
if (option_given_p(opts, tmp)) {
|
602
594
|
VALUE allow_nan = rb_hash_aref(opts, tmp);
|
603
595
|
json->allow_nan = RTEST(allow_nan) ? 1 : 0;
|
604
596
|
} else {
|
605
597
|
json->allow_nan = 0;
|
606
598
|
}
|
607
599
|
tmp = ID2SYM(i_symbolize_names);
|
608
|
-
if (
|
600
|
+
if (option_given_p(opts, tmp)) {
|
609
601
|
VALUE symbolize_names = rb_hash_aref(opts, tmp);
|
610
602
|
json->symbolize_names = RTEST(symbolize_names) ? 1 : 0;
|
611
603
|
} else {
|
612
604
|
json->symbolize_names = 0;
|
613
605
|
}
|
614
606
|
tmp = ID2SYM(i_create_additions);
|
615
|
-
if (
|
607
|
+
if (option_given_p(opts, tmp)) {
|
616
608
|
VALUE create_additions = rb_hash_aref(opts, tmp);
|
617
609
|
if (RTEST(create_additions)) {
|
618
610
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
@@ -623,13 +615,13 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
623
615
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
624
616
|
}
|
625
617
|
tmp = ID2SYM(i_object_class);
|
626
|
-
if (
|
618
|
+
if (option_given_p(opts, tmp)) {
|
627
619
|
json->object_class = rb_hash_aref(opts, tmp);
|
628
620
|
} else {
|
629
621
|
json->object_class = Qnil;
|
630
622
|
}
|
631
623
|
tmp = ID2SYM(i_array_class);
|
632
|
-
if (
|
624
|
+
if (option_given_p(opts, tmp)) {
|
633
625
|
json->array_class = rb_hash_aref(opts, tmp);
|
634
626
|
} else {
|
635
627
|
json->array_class = Qnil;
|
@@ -739,6 +731,7 @@ void Init_parser()
|
|
739
731
|
i_symbolize_names = rb_intern("symbolize_names");
|
740
732
|
i_object_class = rb_intern("object_class");
|
741
733
|
i_array_class = rb_intern("array_class");
|
734
|
+
i_key_p = rb_intern("key?");
|
742
735
|
#ifdef HAVE_RUBY_ENCODING_H
|
743
736
|
mEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
|
744
737
|
mEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
|
data/lib/json/version.rb
CHANGED
data/tests/test_json_addition.rb
CHANGED
@@ -95,7 +95,7 @@ class TC_JSONAddition < Test::Unit::TestCase
|
|
95
95
|
c = C.new
|
96
96
|
assert !C.json_creatable?
|
97
97
|
json = generate(c)
|
98
|
-
assert_raises(ArgumentError) { JSON.parse(json) }
|
98
|
+
assert_raises(ArgumentError, NameError) { JSON.parse(json) }
|
99
99
|
end
|
100
100
|
|
101
101
|
def test_raw_strings
|
@@ -110,11 +110,9 @@ class TC_JSONAddition < Test::Unit::TestCase
|
|
110
110
|
json_raw_object = raw.to_json_raw_object
|
111
111
|
hash = { 'json_class' => 'String', 'raw'=> raw_array }
|
112
112
|
assert_equal hash, json_raw_object
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
# "
|
117
|
-
assert_equal json_raw, json
|
113
|
+
assert_match /\A\{.*\}\Z/, json
|
114
|
+
assert_match /"json_class":"String"/, json
|
115
|
+
assert_match /"raw":\[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255\]/, json
|
118
116
|
raw_again = JSON.parse(json)
|
119
117
|
assert_equal raw, raw_again
|
120
118
|
end
|
data/tests/test_json_rails.rb
CHANGED
@@ -116,7 +116,7 @@ class TC_JSONRails < Test::Unit::TestCase
|
|
116
116
|
c = C.new # with rails addition all objects are theoretically creatable
|
117
117
|
assert C.json_creatable?
|
118
118
|
json = generate(c)
|
119
|
-
assert_raises(ArgumentError) { JSON.parse(json) }
|
119
|
+
assert_raises(ArgumentError, NameError) { JSON.parse(json) }
|
120
120
|
end
|
121
121
|
|
122
122
|
def test_raw_strings
|
@@ -131,11 +131,9 @@ class TC_JSONRails < Test::Unit::TestCase
|
|
131
131
|
json_raw_object = raw.to_json_raw_object
|
132
132
|
hash = { 'json_class' => 'String', 'raw'=> raw_array }
|
133
133
|
assert_equal hash, json_raw_object
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
# "
|
138
|
-
assert_equal json_raw, json
|
134
|
+
assert_match /\A\{.*\}\Z/, json
|
135
|
+
assert_match /"json_class":"String"/, json
|
136
|
+
assert_match /"raw":\[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255\]/, json
|
139
137
|
raw_again = JSON.parse(json)
|
140
138
|
assert_equal raw, raw_again
|
141
139
|
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: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-28 00:00:00 +01:00
|
13
13
|
default_executable: edit_json.rb
|
14
14
|
dependencies: []
|
15
15
|
|