json 1.7.5 → 1.7.6
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/.travis.yml +5 -3
- data/CHANGES +4 -0
- data/Gemfile +1 -8
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +48 -14
- data/ext/json/ext/generator/generator.h +8 -0
- data/ext/json/ext/parser/parser.c +3 -3
- data/ext/json/ext/parser/parser.rl +3 -3
- data/java/src/json/ext/GeneratorState.java +20 -4
- data/java/src/json/ext/Parser.java +2 -2
- data/java/src/json/ext/Parser.rl +2 -2
- data/json.gemspec +4 -4
- data/json_pure.gemspec +4 -4
- data/lib/json/add/bigdecimal.rb +7 -0
- data/lib/json/common.rb +2 -2
- data/lib/json/generic_object.rb +15 -0
- data/lib/json/pure/generator.rb +34 -14
- data/lib/json/pure/parser.rb +3 -3
- data/lib/json/version.rb +1 -1
- data/tests/fixtures/fail18.json +1 -1
- data/tests/test_json.rb +12 -12
- data/tests/test_json_encoding.rb +1 -1
- data/tests/test_json_fixtures.rb +1 -1
- data/tests/test_json_generate.rb +52 -4
- data/tests/test_json_generic_object.rb +12 -1
- data/tests/test_json_string_matching.rb +1 -1
- data/tests/test_json_unicode.rb +1 -1
- metadata +13 -13
data/.travis.yml
CHANGED
@@ -3,15 +3,17 @@ bundler_args: --binstubs
|
|
3
3
|
|
4
4
|
# Specify which ruby versions you wish to run your tests on, each version will be used
|
5
5
|
rvm:
|
6
|
-
- 1.8.6
|
7
6
|
- 1.8.7
|
8
7
|
- 1.9.2
|
9
8
|
- 1.9.3
|
9
|
+
- ree
|
10
10
|
- rbx-18mode
|
11
11
|
- rbx-19mode
|
12
|
-
- ree
|
13
12
|
- jruby-18mode
|
14
13
|
- jruby-19mode
|
15
14
|
- ruby-head
|
16
|
-
|
15
|
+
matrix:
|
16
|
+
allow_failures:
|
17
|
+
- rvm: rbx-18mode
|
18
|
+
- rvm: rbx-19mode
|
17
19
|
script: "bundle exec rake"
|
data/CHANGES
CHANGED
data/Gemfile
CHANGED
@@ -6,11 +6,4 @@ gemspec :name => 'json'
|
|
6
6
|
gemspec :name => 'json_pure'
|
7
7
|
gemspec :name => 'json-java'
|
8
8
|
|
9
|
-
|
10
|
-
gem 'simplecov', :platform => :mri_19
|
11
|
-
gem 'utils'
|
12
|
-
end
|
13
|
-
|
14
|
-
group :test do
|
15
|
-
gem 'test-unit', '~> 2.5', :platform => :mri_19
|
16
|
-
end
|
9
|
+
gem 'utils'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.7.
|
1
|
+
1.7.6
|
@@ -522,7 +522,7 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
522
522
|
unsigned long len;
|
523
523
|
Check_Type(tmp, T_STRING);
|
524
524
|
len = RSTRING_LEN(tmp);
|
525
|
-
state->indent = fstrndup(RSTRING_PTR(tmp), len);
|
525
|
+
state->indent = fstrndup(RSTRING_PTR(tmp), len + 1);
|
526
526
|
state->indent_len = len;
|
527
527
|
}
|
528
528
|
tmp = rb_hash_aref(opts, ID2SYM(i_space));
|
@@ -530,7 +530,7 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
530
530
|
unsigned long len;
|
531
531
|
Check_Type(tmp, T_STRING);
|
532
532
|
len = RSTRING_LEN(tmp);
|
533
|
-
state->space = fstrndup(RSTRING_PTR(tmp), len);
|
533
|
+
state->space = fstrndup(RSTRING_PTR(tmp), len + 1);
|
534
534
|
state->space_len = len;
|
535
535
|
}
|
536
536
|
tmp = rb_hash_aref(opts, ID2SYM(i_space_before));
|
@@ -538,7 +538,7 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
538
538
|
unsigned long len;
|
539
539
|
Check_Type(tmp, T_STRING);
|
540
540
|
len = RSTRING_LEN(tmp);
|
541
|
-
state->space_before = fstrndup(RSTRING_PTR(tmp), len);
|
541
|
+
state->space_before = fstrndup(RSTRING_PTR(tmp), len + 1);
|
542
542
|
state->space_before_len = len;
|
543
543
|
}
|
544
544
|
tmp = rb_hash_aref(opts, ID2SYM(i_array_nl));
|
@@ -546,7 +546,7 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
546
546
|
unsigned long len;
|
547
547
|
Check_Type(tmp, T_STRING);
|
548
548
|
len = RSTRING_LEN(tmp);
|
549
|
-
state->array_nl = fstrndup(RSTRING_PTR(tmp), len);
|
549
|
+
state->array_nl = fstrndup(RSTRING_PTR(tmp), len + 1);
|
550
550
|
state->array_nl_len = len;
|
551
551
|
}
|
552
552
|
tmp = rb_hash_aref(opts, ID2SYM(i_object_nl));
|
@@ -554,11 +554,11 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
554
554
|
unsigned long len;
|
555
555
|
Check_Type(tmp, T_STRING);
|
556
556
|
len = RSTRING_LEN(tmp);
|
557
|
-
state->object_nl = fstrndup(RSTRING_PTR(tmp), len);
|
557
|
+
state->object_nl = fstrndup(RSTRING_PTR(tmp), len + 1);
|
558
558
|
state->object_nl_len = len;
|
559
559
|
}
|
560
560
|
tmp = ID2SYM(i_max_nesting);
|
561
|
-
state->max_nesting =
|
561
|
+
state->max_nesting = 100;
|
562
562
|
if (option_given_p(opts, tmp)) {
|
563
563
|
VALUE max_nesting = rb_hash_aref(opts, tmp);
|
564
564
|
if (RTEST(max_nesting)) {
|
@@ -598,6 +598,18 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
598
598
|
return self;
|
599
599
|
}
|
600
600
|
|
601
|
+
static void set_state_ivars(VALUE hash, VALUE state)
|
602
|
+
{
|
603
|
+
VALUE ivars = rb_obj_instance_variables(state);
|
604
|
+
int i = 0;
|
605
|
+
for (i = 0; i < RARRAY_LEN(ivars); i++) {
|
606
|
+
VALUE key = rb_funcall(rb_ary_entry(ivars, i), i_to_s, 0);
|
607
|
+
long key_len = RSTRING_LEN(key);
|
608
|
+
VALUE value = rb_iv_get(state, StringValueCStr(key));
|
609
|
+
rb_hash_aset(hash, rb_str_intern(rb_str_substr(key, 1, key_len - 1)), value);
|
610
|
+
}
|
611
|
+
}
|
612
|
+
|
601
613
|
/*
|
602
614
|
* call-seq: to_h
|
603
615
|
*
|
@@ -608,6 +620,7 @@ static VALUE cState_to_h(VALUE self)
|
|
608
620
|
{
|
609
621
|
VALUE result = rb_hash_new();
|
610
622
|
GET_STATE(self);
|
623
|
+
set_state_ivars(result, self);
|
611
624
|
rb_hash_aset(result, ID2SYM(i_indent), rb_str_new(state->indent, state->indent_len));
|
612
625
|
rb_hash_aset(result, ID2SYM(i_space), rb_str_new(state->space, state->space_len));
|
613
626
|
rb_hash_aset(result, ID2SYM(i_space_before), rb_str_new(state->space_before, state->space_before_len));
|
@@ -629,14 +642,33 @@ static VALUE cState_to_h(VALUE self)
|
|
629
642
|
*/
|
630
643
|
static VALUE cState_aref(VALUE self, VALUE name)
|
631
644
|
{
|
632
|
-
|
645
|
+
name = rb_funcall(name, i_to_s, 0);
|
633
646
|
if (RTEST(rb_funcall(self, i_respond_to_p, 1, name))) {
|
634
647
|
return rb_funcall(self, i_send, 1, name);
|
635
648
|
} else {
|
636
|
-
return
|
649
|
+
return rb_ivar_get(self, rb_intern_str(rb_str_concat(rb_str_new2("@"), name)));
|
637
650
|
}
|
638
651
|
}
|
639
652
|
|
653
|
+
/*
|
654
|
+
* call-seq: []=(name, value)
|
655
|
+
*
|
656
|
+
* Set the attribute name to value.
|
657
|
+
*/
|
658
|
+
static VALUE cState_aset(VALUE self, VALUE name, VALUE value)
|
659
|
+
{
|
660
|
+
VALUE name_writer;
|
661
|
+
|
662
|
+
name = rb_funcall(name, i_to_s, 0);
|
663
|
+
name_writer = rb_str_cat2(rb_str_dup(name), "=");
|
664
|
+
if (RTEST(rb_funcall(self, i_respond_to_p, 1, name_writer))) {
|
665
|
+
return rb_funcall(self, i_send, 2, name_writer, value);
|
666
|
+
} else {
|
667
|
+
rb_ivar_set(self, rb_intern_str(rb_str_concat(rb_str_new2("@"), name)), value);
|
668
|
+
}
|
669
|
+
return Qnil;
|
670
|
+
}
|
671
|
+
|
640
672
|
static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
|
641
673
|
{
|
642
674
|
char *object_nl = state->object_nl;
|
@@ -908,7 +940,7 @@ static VALUE cState_initialize(int argc, VALUE *argv, VALUE self)
|
|
908
940
|
{
|
909
941
|
VALUE opts;
|
910
942
|
GET_STATE(self);
|
911
|
-
state->max_nesting =
|
943
|
+
state->max_nesting = 100;
|
912
944
|
state->buffer_initial_length = FBUFFER_INITIAL_LENGTH_DEFAULT;
|
913
945
|
rb_scan_args(argc, argv, "01", &opts);
|
914
946
|
if (!NIL_P(opts)) cState_configure(self, opts);
|
@@ -970,7 +1002,7 @@ static VALUE cState_from_state_s(VALUE self, VALUE opts)
|
|
970
1002
|
static VALUE cState_indent(VALUE self)
|
971
1003
|
{
|
972
1004
|
GET_STATE(self);
|
973
|
-
return state->indent ?
|
1005
|
+
return state->indent ? rb_str_new(state->indent, state->indent_len) : rb_str_new2("");
|
974
1006
|
}
|
975
1007
|
|
976
1008
|
/*
|
@@ -1007,7 +1039,7 @@ static VALUE cState_indent_set(VALUE self, VALUE indent)
|
|
1007
1039
|
static VALUE cState_space(VALUE self)
|
1008
1040
|
{
|
1009
1041
|
GET_STATE(self);
|
1010
|
-
return state->space ?
|
1042
|
+
return state->space ? rb_str_new(state->space, state->space_len) : rb_str_new2("");
|
1011
1043
|
}
|
1012
1044
|
|
1013
1045
|
/*
|
@@ -1044,7 +1076,7 @@ static VALUE cState_space_set(VALUE self, VALUE space)
|
|
1044
1076
|
static VALUE cState_space_before(VALUE self)
|
1045
1077
|
{
|
1046
1078
|
GET_STATE(self);
|
1047
|
-
return state->space_before ?
|
1079
|
+
return state->space_before ? rb_str_new(state->space_before, state->space_before_len) : rb_str_new2("");
|
1048
1080
|
}
|
1049
1081
|
|
1050
1082
|
/*
|
@@ -1081,7 +1113,7 @@ static VALUE cState_space_before_set(VALUE self, VALUE space_before)
|
|
1081
1113
|
static VALUE cState_object_nl(VALUE self)
|
1082
1114
|
{
|
1083
1115
|
GET_STATE(self);
|
1084
|
-
return state->object_nl ?
|
1116
|
+
return state->object_nl ? rb_str_new(state->object_nl, state->object_nl_len) : rb_str_new2("");
|
1085
1117
|
}
|
1086
1118
|
|
1087
1119
|
/*
|
@@ -1117,7 +1149,7 @@ static VALUE cState_object_nl_set(VALUE self, VALUE object_nl)
|
|
1117
1149
|
static VALUE cState_array_nl(VALUE self)
|
1118
1150
|
{
|
1119
1151
|
GET_STATE(self);
|
1120
|
-
return state->array_nl ?
|
1152
|
+
return state->array_nl ? rb_str_new(state->array_nl, state->array_nl_len) : rb_str_new2("");
|
1121
1153
|
}
|
1122
1154
|
|
1123
1155
|
/*
|
@@ -1327,7 +1359,9 @@ void Init_generator()
|
|
1327
1359
|
rb_define_method(cState, "configure", cState_configure, 1);
|
1328
1360
|
rb_define_alias(cState, "merge", "configure");
|
1329
1361
|
rb_define_method(cState, "to_h", cState_to_h, 0);
|
1362
|
+
rb_define_alias(cState, "to_hash", "to_h");
|
1330
1363
|
rb_define_method(cState, "[]", cState_aref, 1);
|
1364
|
+
rb_define_method(cState, "[]=", cState_aset, 2);
|
1331
1365
|
rb_define_method(cState, "generate", cState_generate, 1);
|
1332
1366
|
|
1333
1367
|
mGeneratorMethods = rb_define_module_under(mGenerator, "GeneratorMethods");
|
@@ -14,6 +14,14 @@
|
|
14
14
|
#include "re.h"
|
15
15
|
#endif
|
16
16
|
|
17
|
+
#ifndef rb_intern_str
|
18
|
+
#define rb_intern_str(string) SYM2ID(rb_str_intern(string))
|
19
|
+
#endif
|
20
|
+
|
21
|
+
#ifndef rb_obj_instance_variables
|
22
|
+
#define rb_obj_instance_variables(object) rb_funcall(object, rb_intern("instance_variables"), 0)
|
23
|
+
#endif
|
24
|
+
|
17
25
|
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
|
18
26
|
|
19
27
|
/* unicode defintions */
|
@@ -1618,7 +1618,7 @@ static VALUE convert_encoding(VALUE source)
|
|
1618
1618
|
* _opts_ can have the following keys:
|
1619
1619
|
* * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
1620
1620
|
* structures. Disable depth checking with :max_nesting => false|nil|0, it
|
1621
|
-
* defaults to
|
1621
|
+
* defaults to 100.
|
1622
1622
|
* * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
1623
1623
|
* defiance of RFC 4627 to be parsed by the Parser. This option defaults to
|
1624
1624
|
* false.
|
@@ -1655,7 +1655,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1655
1655
|
json->max_nesting = 0;
|
1656
1656
|
}
|
1657
1657
|
} else {
|
1658
|
-
json->max_nesting =
|
1658
|
+
json->max_nesting = 100;
|
1659
1659
|
}
|
1660
1660
|
tmp = ID2SYM(i_allow_nan);
|
1661
1661
|
if (option_given_p(opts, tmp)) {
|
@@ -1709,7 +1709,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1709
1709
|
}
|
1710
1710
|
}
|
1711
1711
|
} else {
|
1712
|
-
json->max_nesting =
|
1712
|
+
json->max_nesting = 100;
|
1713
1713
|
json->allow_nan = 0;
|
1714
1714
|
json->create_additions = 1;
|
1715
1715
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
@@ -602,7 +602,7 @@ static VALUE convert_encoding(VALUE source)
|
|
602
602
|
* _opts_ can have the following keys:
|
603
603
|
* * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
604
604
|
* structures. Disable depth checking with :max_nesting => false|nil|0, it
|
605
|
-
* defaults to
|
605
|
+
* defaults to 100.
|
606
606
|
* * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
607
607
|
* defiance of RFC 4627 to be parsed by the Parser. This option defaults to
|
608
608
|
* false.
|
@@ -639,7 +639,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
639
639
|
json->max_nesting = 0;
|
640
640
|
}
|
641
641
|
} else {
|
642
|
-
json->max_nesting =
|
642
|
+
json->max_nesting = 100;
|
643
643
|
}
|
644
644
|
tmp = ID2SYM(i_allow_nan);
|
645
645
|
if (option_given_p(opts, tmp)) {
|
@@ -693,7 +693,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
693
693
|
}
|
694
694
|
}
|
695
695
|
} else {
|
696
|
-
json->max_nesting =
|
696
|
+
json->max_nesting = 100;
|
697
697
|
json->allow_nan = 0;
|
698
698
|
json->create_additions = 1;
|
699
699
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
@@ -62,7 +62,7 @@ public class GeneratorState extends RubyObject {
|
|
62
62
|
* <code>0</code> means disabled.
|
63
63
|
*/
|
64
64
|
private int maxNesting = DEFAULT_MAX_NESTING;
|
65
|
-
static final int DEFAULT_MAX_NESTING =
|
65
|
+
static final int DEFAULT_MAX_NESTING = 100;
|
66
66
|
/**
|
67
67
|
* Whether special float values (<code>NaN</code>, <code>Infinity</code>,
|
68
68
|
* <code>-Infinity</code>) are accepted.
|
@@ -262,6 +262,19 @@ public class GeneratorState extends RubyObject {
|
|
262
262
|
String name = vName.asJavaString();
|
263
263
|
if (getMetaClass().isMethodBound(name, true)) {
|
264
264
|
return send(context, vName, Block.NULL_BLOCK);
|
265
|
+
} else {
|
266
|
+
return getInstanceVariables().getInstanceVariable("@" + name);
|
267
|
+
}
|
268
|
+
}
|
269
|
+
|
270
|
+
@JRubyMethod(name="[]=", required=2)
|
271
|
+
public IRubyObject op_aset(ThreadContext context, IRubyObject vName, IRubyObject value) {
|
272
|
+
String name = vName.asJavaString();
|
273
|
+
String nameWriter = name + "=";
|
274
|
+
if (getMetaClass().isMethodBound(nameWriter, true)) {
|
275
|
+
return send(context, context.getRuntime().newString(nameWriter), value, Block.NULL_BLOCK);
|
276
|
+
} else {
|
277
|
+
getInstanceVariables().setInstanceVariable("@" + name, value);
|
265
278
|
}
|
266
279
|
return context.getRuntime().getNil();
|
267
280
|
}
|
@@ -445,7 +458,7 @@ public class GeneratorState extends RubyObject {
|
|
445
458
|
* @param vOpts The options hash
|
446
459
|
* @return The receiver
|
447
460
|
*/
|
448
|
-
|
461
|
+
@JRubyMethod(alias = "merge")
|
449
462
|
public IRubyObject configure(ThreadContext context, IRubyObject vOpts) {
|
450
463
|
OptionsReader opts = new OptionsReader(context, vOpts);
|
451
464
|
|
@@ -480,9 +493,9 @@ public class GeneratorState extends RubyObject {
|
|
480
493
|
*
|
481
494
|
* <p>Returns the configuration instance variables as a hash, that can be
|
482
495
|
* passed to the configure method.
|
483
|
-
* @return
|
496
|
+
* @return the hash
|
484
497
|
*/
|
485
|
-
@JRubyMethod
|
498
|
+
@JRubyMethod(alias = "to_hash")
|
486
499
|
public RubyHash to_h(ThreadContext context) {
|
487
500
|
Ruby runtime = context.getRuntime();
|
488
501
|
RubyHash result = RubyHash.newHash(runtime);
|
@@ -498,6 +511,9 @@ public class GeneratorState extends RubyObject {
|
|
498
511
|
result.op_aset(context, runtime.newSymbol("max_nesting"), max_nesting_get(context));
|
499
512
|
result.op_aset(context, runtime.newSymbol("depth"), depth_get(context));
|
500
513
|
result.op_aset(context, runtime.newSymbol("buffer_initial_length"), buffer_initial_length_get(context));
|
514
|
+
for (String name: getInstanceVariableNameList()) {
|
515
|
+
result.op_aset(context, runtime.newSymbol(name.substring(1)), getInstanceVariables().getInstanceVariable(name));
|
516
|
+
}
|
501
517
|
return result;
|
502
518
|
}
|
503
519
|
|
@@ -58,7 +58,7 @@ public class Parser extends RubyObject {
|
|
58
58
|
private RubyClass arrayClass;
|
59
59
|
private RubyHash match_string;
|
60
60
|
|
61
|
-
private static final int DEFAULT_MAX_NESTING =
|
61
|
+
private static final int DEFAULT_MAX_NESTING = 100;
|
62
62
|
|
63
63
|
private static final ByteList JSON_MINUS_INFINITY = new ByteList(ByteList.plain("-Infinity"));
|
64
64
|
// constant names in the JSON module containing those values
|
@@ -113,7 +113,7 @@ public class Parser extends RubyObject {
|
|
113
113
|
* <dt><code>:max_nesting</code>
|
114
114
|
* <dd>The maximum depth of nesting allowed in the parsed data
|
115
115
|
* structures. Disable depth checking with <code>:max_nesting => false|nil|0</code>,
|
116
|
-
* it defaults to
|
116
|
+
* it defaults to 100.
|
117
117
|
*
|
118
118
|
* <dt><code>:allow_nan</code>
|
119
119
|
* <dd>If set to <code>true</code>, allow <code>NaN</code>,
|
data/java/src/json/ext/Parser.rl
CHANGED
@@ -56,7 +56,7 @@ public class Parser extends RubyObject {
|
|
56
56
|
private RubyClass arrayClass;
|
57
57
|
private RubyHash match_string;
|
58
58
|
|
59
|
-
private static final int DEFAULT_MAX_NESTING =
|
59
|
+
private static final int DEFAULT_MAX_NESTING = 100;
|
60
60
|
|
61
61
|
private static final ByteList JSON_MINUS_INFINITY = new ByteList(ByteList.plain("-Infinity"));
|
62
62
|
// constant names in the JSON module containing those values
|
@@ -111,7 +111,7 @@ public class Parser extends RubyObject {
|
|
111
111
|
* <dt><code>:max_nesting</code>
|
112
112
|
* <dd>The maximum depth of nesting allowed in the parsed data
|
113
113
|
* structures. Disable depth checking with <code>:max_nesting => false|nil|0</code>,
|
114
|
-
* it defaults to
|
114
|
+
* it defaults to 100.
|
115
115
|
*
|
116
116
|
* <dt><code>:allow_nan</code>
|
117
117
|
* <dd>If set to <code>true</code>, allow <code>NaN</code>,
|
data/json.gemspec
CHANGED
@@ -2,23 +2,23 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "json"
|
5
|
-
s.version = "1.7.
|
5
|
+
s.version = "1.7.6"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Florian Frank"]
|
9
|
-
s.date = "2012-
|
9
|
+
s.date = "2012-12-31"
|
10
10
|
s.description = "This is a JSON implementation as a Ruby extension in C."
|
11
11
|
s.email = "flori@ping.de"
|
12
12
|
s.extensions = ["ext/json/ext/generator/extconf.rb", "ext/json/ext/parser/extconf.rb"]
|
13
13
|
s.extra_rdoc_files = ["README.rdoc"]
|
14
|
-
s.files = [".gitignore", ".travis.yml", "CHANGES", "COPYING", "COPYING-json-jruby", "GPL", "Gemfile", "README-json-jruby.markdown", "README.rdoc", "Rakefile", "TODO", "VERSION", "data/example.json", "data/index.html", "data/prototype.js", "diagrams/.keep", "ext/json/ext/fbuffer/fbuffer.h", "ext/json/ext/generator/depend", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/generator.h", "ext/json/ext/parser/depend", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.c", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/parser.rl", "install.rb", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/GeneratorMethods.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/Parser.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/ParserService.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/Utils.java", "json-java.gemspec", "json.gemspec", "json_pure.gemspec", "lib/json.rb", "lib/json/add/bigdecimal.rb", "lib/json/add/complex.rb", "lib/json/add/core.rb", "lib/json/add/date.rb", "lib/json/add/date_time.rb", "lib/json/add/exception.rb", "lib/json/add/ostruct.rb", "lib/json/add/range.rb", "lib/json/add/rational.rb", "lib/json/add/regexp.rb", "lib/json/add/struct.rb", "lib/json/add/symbol.rb", "lib/json/add/time.rb", "lib/json/common.rb", "lib/json/ext.rb", "lib/json/ext/.keep", "lib/json/generic_object.rb", "lib/json/pure.rb", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/version.rb", "tests/fixtures/fail1.json", "tests/fixtures/fail10.json", "tests/fixtures/fail11.json", "tests/fixtures/fail12.json", "tests/fixtures/fail13.json", "tests/fixtures/fail14.json", "tests/fixtures/fail18.json", "tests/fixtures/fail19.json", "tests/fixtures/fail2.json", "tests/fixtures/fail20.json", "tests/fixtures/fail21.json", "tests/fixtures/fail22.json", "tests/fixtures/fail23.json", "tests/fixtures/fail24.json", "tests/fixtures/fail25.json", "tests/fixtures/fail27.json", "tests/fixtures/fail28.json", "tests/fixtures/fail3.json", "tests/fixtures/fail4.json", "tests/fixtures/fail5.json", "tests/fixtures/fail6.json", "tests/fixtures/fail7.json", "tests/fixtures/fail8.json", "tests/fixtures/fail9.json", "tests/fixtures/pass1.json", "tests/fixtures/pass15.json", "tests/fixtures/pass16.json", "tests/fixtures/pass17.json", "tests/fixtures/pass2.json", "tests/fixtures/pass26.json", "tests/fixtures/pass3.json", "tests/setup_variant.rb", "tests/test_json.rb", "tests/test_json_addition.rb", "tests/test_json_encoding.rb", "tests/test_json_fixtures.rb", "tests/test_json_generate.rb", "tests/test_json_generic_object.rb", "tests/test_json_string_matching.rb", "tests/test_json_unicode.rb", "tools/fuzz.rb", "tools/server.rb", "./tests/
|
14
|
+
s.files = [".gitignore", ".travis.yml", "CHANGES", "COPYING", "COPYING-json-jruby", "GPL", "Gemfile", "README-json-jruby.markdown", "README.rdoc", "Rakefile", "TODO", "VERSION", "data/example.json", "data/index.html", "data/prototype.js", "diagrams/.keep", "ext/json/ext/fbuffer/fbuffer.h", "ext/json/ext/generator/depend", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/generator.h", "ext/json/ext/parser/depend", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.c", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/parser.rl", "install.rb", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/GeneratorMethods.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/Parser.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/ParserService.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/Utils.java", "json-java.gemspec", "json.gemspec", "json_pure.gemspec", "lib/json.rb", "lib/json/add/bigdecimal.rb", "lib/json/add/complex.rb", "lib/json/add/core.rb", "lib/json/add/date.rb", "lib/json/add/date_time.rb", "lib/json/add/exception.rb", "lib/json/add/ostruct.rb", "lib/json/add/range.rb", "lib/json/add/rational.rb", "lib/json/add/regexp.rb", "lib/json/add/struct.rb", "lib/json/add/symbol.rb", "lib/json/add/time.rb", "lib/json/common.rb", "lib/json/ext.rb", "lib/json/ext/.keep", "lib/json/generic_object.rb", "lib/json/pure.rb", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/version.rb", "tests/fixtures/fail1.json", "tests/fixtures/fail10.json", "tests/fixtures/fail11.json", "tests/fixtures/fail12.json", "tests/fixtures/fail13.json", "tests/fixtures/fail14.json", "tests/fixtures/fail18.json", "tests/fixtures/fail19.json", "tests/fixtures/fail2.json", "tests/fixtures/fail20.json", "tests/fixtures/fail21.json", "tests/fixtures/fail22.json", "tests/fixtures/fail23.json", "tests/fixtures/fail24.json", "tests/fixtures/fail25.json", "tests/fixtures/fail27.json", "tests/fixtures/fail28.json", "tests/fixtures/fail3.json", "tests/fixtures/fail4.json", "tests/fixtures/fail5.json", "tests/fixtures/fail6.json", "tests/fixtures/fail7.json", "tests/fixtures/fail8.json", "tests/fixtures/fail9.json", "tests/fixtures/pass1.json", "tests/fixtures/pass15.json", "tests/fixtures/pass16.json", "tests/fixtures/pass17.json", "tests/fixtures/pass2.json", "tests/fixtures/pass26.json", "tests/fixtures/pass3.json", "tests/setup_variant.rb", "tests/test_json.rb", "tests/test_json_addition.rb", "tests/test_json_encoding.rb", "tests/test_json_fixtures.rb", "tests/test_json_generate.rb", "tests/test_json_generic_object.rb", "tests/test_json_string_matching.rb", "tests/test_json_unicode.rb", "tools/fuzz.rb", "tools/server.rb", "./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json_generic_object.rb", "./tests/test_json.rb"]
|
15
15
|
s.homepage = "http://flori.github.com/json"
|
16
16
|
s.rdoc_options = ["--title", "JSON implemention for Ruby", "--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = "json"
|
19
19
|
s.rubygems_version = "1.8.24"
|
20
20
|
s.summary = "JSON Implementation for Ruby"
|
21
|
-
s.test_files = ["./tests/
|
21
|
+
s.test_files = ["./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json_generic_object.rb", "./tests/test_json.rb"]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
24
|
s.specification_version = 3
|
data/json_pure.gemspec
CHANGED
@@ -2,22 +2,22 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "json_pure"
|
5
|
-
s.version = "1.7.
|
5
|
+
s.version = "1.7.6"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Florian Frank"]
|
9
|
-
s.date = "2012-
|
9
|
+
s.date = "2012-12-31"
|
10
10
|
s.description = "This is a JSON implementation in pure Ruby."
|
11
11
|
s.email = "flori@ping.de"
|
12
12
|
s.extra_rdoc_files = ["README.rdoc"]
|
13
|
-
s.files = [".gitignore", ".travis.yml", "CHANGES", "COPYING", "COPYING-json-jruby", "GPL", "Gemfile", "README-json-jruby.markdown", "README.rdoc", "Rakefile", "TODO", "VERSION", "data/example.json", "data/index.html", "data/prototype.js", "diagrams/.keep", "ext/json/ext/fbuffer/fbuffer.h", "ext/json/ext/generator/depend", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/generator.h", "ext/json/ext/parser/depend", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.c", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/parser.rl", "install.rb", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/GeneratorMethods.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/Parser.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/ParserService.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/Utils.java", "json-java.gemspec", "json.gemspec", "json_pure.gemspec", "lib/json.rb", "lib/json/add/bigdecimal.rb", "lib/json/add/complex.rb", "lib/json/add/core.rb", "lib/json/add/date.rb", "lib/json/add/date_time.rb", "lib/json/add/exception.rb", "lib/json/add/ostruct.rb", "lib/json/add/range.rb", "lib/json/add/rational.rb", "lib/json/add/regexp.rb", "lib/json/add/struct.rb", "lib/json/add/symbol.rb", "lib/json/add/time.rb", "lib/json/common.rb", "lib/json/ext.rb", "lib/json/ext/.keep", "lib/json/generic_object.rb", "lib/json/pure.rb", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/version.rb", "tests/fixtures/fail1.json", "tests/fixtures/fail10.json", "tests/fixtures/fail11.json", "tests/fixtures/fail12.json", "tests/fixtures/fail13.json", "tests/fixtures/fail14.json", "tests/fixtures/fail18.json", "tests/fixtures/fail19.json", "tests/fixtures/fail2.json", "tests/fixtures/fail20.json", "tests/fixtures/fail21.json", "tests/fixtures/fail22.json", "tests/fixtures/fail23.json", "tests/fixtures/fail24.json", "tests/fixtures/fail25.json", "tests/fixtures/fail27.json", "tests/fixtures/fail28.json", "tests/fixtures/fail3.json", "tests/fixtures/fail4.json", "tests/fixtures/fail5.json", "tests/fixtures/fail6.json", "tests/fixtures/fail7.json", "tests/fixtures/fail8.json", "tests/fixtures/fail9.json", "tests/fixtures/pass1.json", "tests/fixtures/pass15.json", "tests/fixtures/pass16.json", "tests/fixtures/pass17.json", "tests/fixtures/pass2.json", "tests/fixtures/pass26.json", "tests/fixtures/pass3.json", "tests/setup_variant.rb", "tests/test_json.rb", "tests/test_json_addition.rb", "tests/test_json_encoding.rb", "tests/test_json_fixtures.rb", "tests/test_json_generate.rb", "tests/test_json_generic_object.rb", "tests/test_json_string_matching.rb", "tests/test_json_unicode.rb", "tools/fuzz.rb", "tools/server.rb", "./tests/
|
13
|
+
s.files = [".gitignore", ".travis.yml", "CHANGES", "COPYING", "COPYING-json-jruby", "GPL", "Gemfile", "README-json-jruby.markdown", "README.rdoc", "Rakefile", "TODO", "VERSION", "data/example.json", "data/index.html", "data/prototype.js", "diagrams/.keep", "ext/json/ext/fbuffer/fbuffer.h", "ext/json/ext/generator/depend", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/generator.h", "ext/json/ext/parser/depend", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.c", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/parser.rl", "install.rb", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/GeneratorMethods.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/Parser.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/ParserService.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/Utils.java", "json-java.gemspec", "json.gemspec", "json_pure.gemspec", "lib/json.rb", "lib/json/add/bigdecimal.rb", "lib/json/add/complex.rb", "lib/json/add/core.rb", "lib/json/add/date.rb", "lib/json/add/date_time.rb", "lib/json/add/exception.rb", "lib/json/add/ostruct.rb", "lib/json/add/range.rb", "lib/json/add/rational.rb", "lib/json/add/regexp.rb", "lib/json/add/struct.rb", "lib/json/add/symbol.rb", "lib/json/add/time.rb", "lib/json/common.rb", "lib/json/ext.rb", "lib/json/ext/.keep", "lib/json/generic_object.rb", "lib/json/pure.rb", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/version.rb", "tests/fixtures/fail1.json", "tests/fixtures/fail10.json", "tests/fixtures/fail11.json", "tests/fixtures/fail12.json", "tests/fixtures/fail13.json", "tests/fixtures/fail14.json", "tests/fixtures/fail18.json", "tests/fixtures/fail19.json", "tests/fixtures/fail2.json", "tests/fixtures/fail20.json", "tests/fixtures/fail21.json", "tests/fixtures/fail22.json", "tests/fixtures/fail23.json", "tests/fixtures/fail24.json", "tests/fixtures/fail25.json", "tests/fixtures/fail27.json", "tests/fixtures/fail28.json", "tests/fixtures/fail3.json", "tests/fixtures/fail4.json", "tests/fixtures/fail5.json", "tests/fixtures/fail6.json", "tests/fixtures/fail7.json", "tests/fixtures/fail8.json", "tests/fixtures/fail9.json", "tests/fixtures/pass1.json", "tests/fixtures/pass15.json", "tests/fixtures/pass16.json", "tests/fixtures/pass17.json", "tests/fixtures/pass2.json", "tests/fixtures/pass26.json", "tests/fixtures/pass3.json", "tests/setup_variant.rb", "tests/test_json.rb", "tests/test_json_addition.rb", "tests/test_json_encoding.rb", "tests/test_json_fixtures.rb", "tests/test_json_generate.rb", "tests/test_json_generic_object.rb", "tests/test_json_string_matching.rb", "tests/test_json_unicode.rb", "tools/fuzz.rb", "tools/server.rb", "./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json_generic_object.rb", "./tests/test_json.rb"]
|
14
14
|
s.homepage = "http://flori.github.com/json"
|
15
15
|
s.rdoc_options = ["--title", "JSON implemention for ruby", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = "json"
|
18
18
|
s.rubygems_version = "1.8.24"
|
19
19
|
s.summary = "JSON Implementation for Ruby"
|
20
|
-
s.test_files = ["./tests/
|
20
|
+
s.test_files = ["./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json_generic_object.rb", "./tests/test_json.rb"]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
s.specification_version = 3
|
data/lib/json/add/bigdecimal.rb
CHANGED
@@ -4,10 +4,16 @@ end
|
|
4
4
|
defined?(::BigDecimal) or require 'bigdecimal'
|
5
5
|
|
6
6
|
class BigDecimal
|
7
|
+
# Import a JSON Marshalled object.
|
8
|
+
#
|
9
|
+
# method used for JSON marshalling support.
|
7
10
|
def self.json_create(object)
|
8
11
|
BigDecimal._load object['b']
|
9
12
|
end
|
10
13
|
|
14
|
+
# Marshal the object to JSON.
|
15
|
+
#
|
16
|
+
# method used for JSON marshalling support.
|
11
17
|
def as_json(*)
|
12
18
|
{
|
13
19
|
JSON.create_id => self.class.name,
|
@@ -15,6 +21,7 @@ class BigDecimal
|
|
15
21
|
}
|
16
22
|
end
|
17
23
|
|
24
|
+
# return the JSON value
|
18
25
|
def to_json(*)
|
19
26
|
as_json.to_json
|
20
27
|
end
|
data/lib/json/common.rb
CHANGED
@@ -139,7 +139,7 @@ module JSON
|
|
139
139
|
# keys:
|
140
140
|
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
141
141
|
# structures. Disable depth checking with :max_nesting => false. It defaults
|
142
|
-
# to
|
142
|
+
# to 100.
|
143
143
|
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
144
144
|
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
|
145
145
|
# to false.
|
@@ -199,7 +199,7 @@ module JSON
|
|
199
199
|
# encountered. This options defaults to false.
|
200
200
|
# * *max_nesting*: The maximum depth of nesting allowed in the data
|
201
201
|
# structures from which JSON is to be generated. Disable depth checking
|
202
|
-
# with :max_nesting => false, it defaults to
|
202
|
+
# with :max_nesting => false, it defaults to 100.
|
203
203
|
#
|
204
204
|
# See also the fast_generate for the fastest creation method with the least
|
205
205
|
# amount of sanity checks, and the pretty_generate method for some
|
data/lib/json/generic_object.rb
CHANGED
@@ -10,6 +10,21 @@ module JSON
|
|
10
10
|
data.delete JSON.create_id
|
11
11
|
self[data]
|
12
12
|
end
|
13
|
+
|
14
|
+
def from_hash(object)
|
15
|
+
case
|
16
|
+
when object.respond_to?(:to_hash)
|
17
|
+
result = new
|
18
|
+
object.to_hash.each do |key, value|
|
19
|
+
result[key] = from_hash(value)
|
20
|
+
end
|
21
|
+
result
|
22
|
+
when object.respond_to?(:to_ary)
|
23
|
+
object.to_ary.map { |a| from_hash(a) }
|
24
|
+
else
|
25
|
+
object
|
26
|
+
end
|
27
|
+
end
|
13
28
|
end
|
14
29
|
|
15
30
|
def to_hash
|
data/lib/json/pure/generator.rb
CHANGED
@@ -220,17 +220,22 @@ module JSON
|
|
220
220
|
# Configure this State instance with the Hash _opts_, and return
|
221
221
|
# itself.
|
222
222
|
def configure(opts)
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
@
|
227
|
-
@
|
228
|
-
@
|
229
|
-
@
|
230
|
-
@
|
231
|
-
@
|
232
|
-
if
|
233
|
-
|
223
|
+
for key, value in opts
|
224
|
+
instance_variable_set "@#{key}", value
|
225
|
+
end
|
226
|
+
@indent = opts[:indent] if opts.key?(:indent)
|
227
|
+
@space = opts[:space] if opts.key?(:space)
|
228
|
+
@space_before = opts[:space_before] if opts.key?(:space_before)
|
229
|
+
@object_nl = opts[:object_nl] if opts.key?(:object_nl)
|
230
|
+
@array_nl = opts[:array_nl] if opts.key?(:array_nl)
|
231
|
+
@allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan)
|
232
|
+
@ascii_only = opts[:ascii_only] if opts.key?(:ascii_only)
|
233
|
+
@depth = opts[:depth] || 0
|
234
|
+
@quirks_mode = opts[:quirks_mode] if opts.key?(:quirks_mode)
|
235
|
+
@buffer_initial_length ||= opts[:buffer_initial_length]
|
236
|
+
|
237
|
+
if !opts.key?(:max_nesting) # defaults to 100
|
238
|
+
@max_nesting = 100
|
234
239
|
elsif opts[:max_nesting]
|
235
240
|
@max_nesting = opts[:max_nesting]
|
236
241
|
else
|
@@ -244,12 +249,15 @@ module JSON
|
|
244
249
|
# passed to the configure method.
|
245
250
|
def to_h
|
246
251
|
result = {}
|
247
|
-
for iv in
|
248
|
-
|
252
|
+
for iv in instance_variables
|
253
|
+
iv = iv.to_s[1..-1]
|
254
|
+
result[iv.to_sym] = self[iv]
|
249
255
|
end
|
250
256
|
result
|
251
257
|
end
|
252
258
|
|
259
|
+
alias to_hash to_h
|
260
|
+
|
253
261
|
# Generates a valid JSON document from object +obj+ and returns the
|
254
262
|
# result. If no valid JSON document can be created this method raises a
|
255
263
|
# GeneratorError exception.
|
@@ -267,7 +275,19 @@ module JSON
|
|
267
275
|
|
268
276
|
# Return the value returned by method +name+.
|
269
277
|
def [](name)
|
270
|
-
|
278
|
+
if respond_to?(name)
|
279
|
+
__send__(name)
|
280
|
+
else
|
281
|
+
instance_variable_get("@#{name}")
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def []=(name, value)
|
286
|
+
if respond_to?(name_writer = "#{name}=")
|
287
|
+
__send__ name_writer, value
|
288
|
+
else
|
289
|
+
instance_variable_set "@#{name}", value
|
290
|
+
end
|
271
291
|
end
|
272
292
|
end
|
273
293
|
|
data/lib/json/pure/parser.rb
CHANGED
@@ -56,7 +56,7 @@ module JSON
|
|
56
56
|
# keys:
|
57
57
|
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
58
58
|
# structures. Disable depth checking with :max_nesting => false|nil|0,
|
59
|
-
# it defaults to
|
59
|
+
# it defaults to 100.
|
60
60
|
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
61
61
|
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
|
62
62
|
# to false.
|
@@ -76,8 +76,8 @@ module JSON
|
|
76
76
|
source = convert_encoding source
|
77
77
|
end
|
78
78
|
super source
|
79
|
-
if !opts.key?(:max_nesting) # defaults to
|
80
|
-
@max_nesting =
|
79
|
+
if !opts.key?(:max_nesting) # defaults to 100
|
80
|
+
@max_nesting = 100
|
81
81
|
elsif opts[:max_nesting]
|
82
82
|
@max_nesting = opts[:max_nesting]
|
83
83
|
else
|
data/lib/json/version.rb
CHANGED
data/tests/fixtures/fail18.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
|
1
|
+
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
|
data/tests/test_json.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# encoding: utf-8
|
3
3
|
|
4
4
|
require 'test/unit'
|
5
5
|
require File.join(File.dirname(__FILE__), 'setup_variant')
|
@@ -446,12 +446,12 @@ EOT
|
|
446
446
|
assert_raises(JSON::NestingError) { JSON.parse '[[]]', :max_nesting => 1 }
|
447
447
|
assert_raises(JSON::NestingError) { JSON.parser.new('[[]]', :max_nesting => 1).parse }
|
448
448
|
assert_equal [[]], JSON.parse('[[]]', :max_nesting => 2)
|
449
|
-
too_deep = '[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]'
|
449
|
+
too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
450
450
|
too_deep_ary = eval too_deep
|
451
451
|
assert_raises(JSON::NestingError) { JSON.parse too_deep }
|
452
452
|
assert_raises(JSON::NestingError) { JSON.parser.new(too_deep).parse }
|
453
|
-
assert_raises(JSON::NestingError) { JSON.parse too_deep, :max_nesting =>
|
454
|
-
ok = JSON.parse too_deep, :max_nesting =>
|
453
|
+
assert_raises(JSON::NestingError) { JSON.parse too_deep, :max_nesting => 100 }
|
454
|
+
ok = JSON.parse too_deep, :max_nesting => 101
|
455
455
|
assert_equal too_deep_ary, ok
|
456
456
|
ok = JSON.parse too_deep, :max_nesting => nil
|
457
457
|
assert_equal too_deep_ary, ok
|
@@ -462,8 +462,8 @@ EOT
|
|
462
462
|
assert_raises(JSON::NestingError) { JSON.generate [[]], :max_nesting => 1 }
|
463
463
|
assert_equal '[[]]', JSON.generate([[]], :max_nesting => 2)
|
464
464
|
assert_raises(JSON::NestingError) { JSON.generate too_deep_ary }
|
465
|
-
assert_raises(JSON::NestingError) { JSON.generate too_deep_ary, :max_nesting =>
|
466
|
-
ok = JSON.generate too_deep_ary, :max_nesting =>
|
465
|
+
assert_raises(JSON::NestingError) { JSON.generate too_deep_ary, :max_nesting => 100 }
|
466
|
+
ok = JSON.generate too_deep_ary, :max_nesting => 101
|
467
467
|
assert_equal too_deep, ok
|
468
468
|
ok = JSON.generate too_deep_ary, :max_nesting => nil
|
469
469
|
assert_equal too_deep, ok
|
@@ -494,18 +494,18 @@ EOT
|
|
494
494
|
end
|
495
495
|
|
496
496
|
def test_dump
|
497
|
-
too_deep = '[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]'
|
497
|
+
too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
498
498
|
assert_equal too_deep, JSON.dump(eval(too_deep))
|
499
499
|
assert_kind_of String, Marshal.dump(eval(too_deep))
|
500
|
-
assert_raises(ArgumentError) { JSON.dump(eval(too_deep),
|
501
|
-
assert_raises(ArgumentError) { Marshal.dump(eval(too_deep),
|
502
|
-
assert_equal too_deep, JSON.dump(eval(too_deep),
|
503
|
-
assert_kind_of String, Marshal.dump(eval(too_deep),
|
500
|
+
assert_raises(ArgumentError) { JSON.dump(eval(too_deep), 100) }
|
501
|
+
assert_raises(ArgumentError) { Marshal.dump(eval(too_deep), 100) }
|
502
|
+
assert_equal too_deep, JSON.dump(eval(too_deep), 101)
|
503
|
+
assert_kind_of String, Marshal.dump(eval(too_deep), 101)
|
504
504
|
output = StringIO.new
|
505
505
|
JSON.dump(eval(too_deep), output)
|
506
506
|
assert_equal too_deep, output.string
|
507
507
|
output = StringIO.new
|
508
|
-
JSON.dump(eval(too_deep), output,
|
508
|
+
JSON.dump(eval(too_deep), output, 101)
|
509
509
|
assert_equal too_deep, output.string
|
510
510
|
end
|
511
511
|
|
data/tests/test_json_encoding.rb
CHANGED
data/tests/test_json_fixtures.rb
CHANGED
data/tests/test_json_generate.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# encoding: utf-8
|
3
3
|
|
4
4
|
require 'test/unit'
|
5
5
|
require File.join(File.dirname(__FILE__), 'setup_variant')
|
@@ -130,7 +130,7 @@ EOT
|
|
130
130
|
:quirks_mode => false,
|
131
131
|
:depth => 0,
|
132
132
|
:indent => " ",
|
133
|
-
:max_nesting =>
|
133
|
+
:max_nesting => 100,
|
134
134
|
:object_nl => "\n",
|
135
135
|
:space => " ",
|
136
136
|
:space_before => "",
|
@@ -147,7 +147,7 @@ EOT
|
|
147
147
|
:quirks_mode => false,
|
148
148
|
:depth => 0,
|
149
149
|
:indent => "",
|
150
|
-
:max_nesting =>
|
150
|
+
:max_nesting => 100,
|
151
151
|
:object_nl => "",
|
152
152
|
:space => "",
|
153
153
|
:space_before => "",
|
@@ -200,7 +200,7 @@ EOT
|
|
200
200
|
s = JSON.state.new
|
201
201
|
assert_equal 0, s.depth
|
202
202
|
assert_raises(JSON::NestingError) { ary.to_json(s) }
|
203
|
-
assert_equal
|
203
|
+
assert_equal 100, s.depth
|
204
204
|
end
|
205
205
|
|
206
206
|
def test_buffer_initial_length
|
@@ -227,6 +227,30 @@ EOT
|
|
227
227
|
GC.stress = stress
|
228
228
|
end if GC.respond_to?(:stress=)
|
229
229
|
|
230
|
+
def test_configure_using_configure_and_merge
|
231
|
+
numbered_state = {
|
232
|
+
:indent => "1",
|
233
|
+
:space => '2',
|
234
|
+
:space_before => '3',
|
235
|
+
:object_nl => '4',
|
236
|
+
:array_nl => '5'
|
237
|
+
}
|
238
|
+
state1 = JSON.state.new
|
239
|
+
state1.merge(numbered_state)
|
240
|
+
assert_equal '1', state1.indent
|
241
|
+
assert_equal '2', state1.space
|
242
|
+
assert_equal '3', state1.space_before
|
243
|
+
assert_equal '4', state1.object_nl
|
244
|
+
assert_equal '5', state1.array_nl
|
245
|
+
state2 = JSON.state.new
|
246
|
+
state2.configure(numbered_state)
|
247
|
+
assert_equal '1', state2.indent
|
248
|
+
assert_equal '2', state2.space
|
249
|
+
assert_equal '3', state2.space_before
|
250
|
+
assert_equal '4', state2.object_nl
|
251
|
+
assert_equal '5', state2.array_nl
|
252
|
+
end
|
253
|
+
|
230
254
|
if defined?(JSON::Ext::Generator)
|
231
255
|
def test_broken_bignum # [ruby-core:38867]
|
232
256
|
pid = fork do
|
@@ -248,4 +272,28 @@ EOT
|
|
248
272
|
# introducing race conditions of tests are run in parallel
|
249
273
|
end
|
250
274
|
end
|
275
|
+
|
276
|
+
def test_hash_likeness_set_symbol
|
277
|
+
state = JSON.state.new
|
278
|
+
assert_equal nil, state[:foo]
|
279
|
+
assert_equal nil, state['foo']
|
280
|
+
state[:foo] = :bar
|
281
|
+
assert_equal :bar, state[:foo]
|
282
|
+
assert_equal :bar, state['foo']
|
283
|
+
state_hash = state.to_hash
|
284
|
+
assert_kind_of Hash, state_hash
|
285
|
+
assert_equal :bar, state_hash[:foo]
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_hash_likeness_set_string
|
289
|
+
state = JSON.state.new
|
290
|
+
assert_equal nil, state[:foo]
|
291
|
+
assert_equal nil, state['foo']
|
292
|
+
state['foo'] = :bar
|
293
|
+
assert_equal :bar, state[:foo]
|
294
|
+
assert_equal :bar, state['foo']
|
295
|
+
state_hash = state.to_hash
|
296
|
+
assert_kind_of Hash, state_hash
|
297
|
+
assert_equal :bar, state_hash[:foo]
|
298
|
+
end
|
251
299
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# encoding: utf-8
|
3
3
|
|
4
4
|
require 'test/unit'
|
5
5
|
require File.join(File.dirname(__FILE__), 'setup_variant')
|
@@ -32,4 +32,15 @@ class TestJSONGenericObject < Test::Unit::TestCase
|
|
32
32
|
l = JSON('{ "a": { "b": 2 } }', :object_class => GenericObject)
|
33
33
|
assert_equal 2, l.a.b
|
34
34
|
end
|
35
|
+
|
36
|
+
def test_from_hash
|
37
|
+
result = GenericObject.from_hash(
|
38
|
+
:foo => { :bar => { :baz => true }, :quux => [ { :foobar => true } ] })
|
39
|
+
assert_kind_of GenericObject, result.foo
|
40
|
+
assert_kind_of GenericObject, result.foo.bar
|
41
|
+
assert_equal true, result.foo.bar.baz
|
42
|
+
assert_kind_of GenericObject, result.foo.quux.first
|
43
|
+
assert_equal true, result.foo.quux.first.foobar
|
44
|
+
assert_equal true, GenericObject.from_hash(true)
|
45
|
+
end
|
35
46
|
end
|
data/tests/test_json_unicode.rb
CHANGED
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.7.
|
4
|
+
version: 1.7.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: permutation
|
@@ -159,14 +159,14 @@ files:
|
|
159
159
|
- tests/test_json_unicode.rb
|
160
160
|
- tools/fuzz.rb
|
161
161
|
- tools/server.rb
|
162
|
-
- ./tests/
|
163
|
-
- ./tests/test_json_addition.rb
|
164
|
-
- ./tests/test_json_encoding.rb
|
162
|
+
- ./tests/test_json_string_matching.rb
|
165
163
|
- ./tests/test_json_fixtures.rb
|
164
|
+
- ./tests/test_json_unicode.rb
|
165
|
+
- ./tests/test_json_addition.rb
|
166
166
|
- ./tests/test_json_generate.rb
|
167
|
+
- ./tests/test_json_encoding.rb
|
167
168
|
- ./tests/test_json_generic_object.rb
|
168
|
-
- ./tests/
|
169
|
-
- ./tests/test_json_unicode.rb
|
169
|
+
- ./tests/test_json.rb
|
170
170
|
homepage: http://flori.github.com/json
|
171
171
|
licenses: []
|
172
172
|
post_install_message:
|
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
segments:
|
187
187
|
- 0
|
188
|
-
hash: -
|
188
|
+
hash: -365926163349180863
|
189
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
190
|
none: false
|
191
191
|
requirements:
|
@@ -199,11 +199,11 @@ signing_key:
|
|
199
199
|
specification_version: 3
|
200
200
|
summary: JSON Implementation for Ruby
|
201
201
|
test_files:
|
202
|
-
- ./tests/
|
203
|
-
- ./tests/test_json_addition.rb
|
204
|
-
- ./tests/test_json_encoding.rb
|
202
|
+
- ./tests/test_json_string_matching.rb
|
205
203
|
- ./tests/test_json_fixtures.rb
|
204
|
+
- ./tests/test_json_unicode.rb
|
205
|
+
- ./tests/test_json_addition.rb
|
206
206
|
- ./tests/test_json_generate.rb
|
207
|
+
- ./tests/test_json_encoding.rb
|
207
208
|
- ./tests/test_json_generic_object.rb
|
208
|
-
- ./tests/
|
209
|
-
- ./tests/test_json_unicode.rb
|
209
|
+
- ./tests/test_json.rb
|