oj 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of oj might be problematic. Click here for more details.
- data/README.md +2 -4
- data/ext/oj/dump.c +31 -0
- data/ext/oj/load.c +4 -16
- data/ext/oj/oj.c +2 -3
- data/lib/oj/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -24,11 +24,9 @@ A fast JSON parser and Object marshaller as a Ruby gem.
|
|
24
24
|
|
25
25
|
## <a name="release">Release Notes</a>
|
26
26
|
|
27
|
-
### Release 1.0.
|
27
|
+
### Release 1.0.4
|
28
28
|
|
29
|
-
-
|
30
|
-
|
31
|
-
- The load() method now supports IO Objects as input as well as Strings.
|
29
|
+
- Fixed bug that did not allow symbols as keys in :compat mode.
|
32
30
|
|
33
31
|
## <a name="description">Description</a>
|
34
32
|
|
data/ext/oj/dump.c
CHANGED
@@ -76,6 +76,7 @@ static void dump_class_comp(VALUE obj, Out out);
|
|
76
76
|
static void dump_class_obj(VALUE obj, Out out);
|
77
77
|
static void dump_array(VALUE obj, int depth, Out out);
|
78
78
|
static int hash_cb_strict(VALUE key, VALUE value, Out out);
|
79
|
+
static int hash_cb_compat(VALUE key, VALUE value, Out out);
|
79
80
|
static int hash_cb_object(VALUE key, VALUE value, Out out);
|
80
81
|
static void dump_hash(VALUE obj, int depth, int mode, Out out);
|
81
82
|
static void dump_time(VALUE obj, Out out);
|
@@ -542,6 +543,34 @@ hash_cb_strict(VALUE key, VALUE value, Out out) {
|
|
542
543
|
return ST_CONTINUE;
|
543
544
|
}
|
544
545
|
|
546
|
+
static int
|
547
|
+
hash_cb_compat(VALUE key, VALUE value, Out out) {
|
548
|
+
int depth = out->depth;
|
549
|
+
long size = depth * out->indent + 1;
|
550
|
+
|
551
|
+
if (out->end - out->cur <= size) {
|
552
|
+
grow(out, size);
|
553
|
+
}
|
554
|
+
fill_indent(out, depth);
|
555
|
+
switch (rb_type(key)) {
|
556
|
+
case T_STRING:
|
557
|
+
dump_str_comp(key, out);
|
558
|
+
break;
|
559
|
+
case T_SYMBOL:
|
560
|
+
dump_sym_comp(key, out);
|
561
|
+
break;
|
562
|
+
default:
|
563
|
+
rb_raise(rb_eTypeError, "In :strict mode all Hash keys must be Strings.");
|
564
|
+
break;
|
565
|
+
}
|
566
|
+
*out->cur++ = ':';
|
567
|
+
dump_val(value, depth, out);
|
568
|
+
out->depth = depth;
|
569
|
+
*out->cur++ = ',';
|
570
|
+
|
571
|
+
return ST_CONTINUE;
|
572
|
+
}
|
573
|
+
|
545
574
|
static int
|
546
575
|
hash_cb_object(VALUE key, VALUE value, Out out) {
|
547
576
|
int depth = out->depth;
|
@@ -639,6 +668,8 @@ dump_hash(VALUE obj, int depth, int mode, Out out) {
|
|
639
668
|
out->depth = depth + 1;
|
640
669
|
if (ObjectMode == mode) {
|
641
670
|
rb_hash_foreach(obj, hash_cb_object, (VALUE)out);
|
671
|
+
} else if (CompatMode == mode) {
|
672
|
+
rb_hash_foreach(obj, hash_cb_compat, (VALUE)out);
|
642
673
|
} else {
|
643
674
|
rb_hash_foreach(obj, hash_cb_strict, (VALUE)out);
|
644
675
|
}
|
data/ext/oj/load.c
CHANGED
@@ -335,6 +335,7 @@ read_obj(ParseInfo pi) {
|
|
335
335
|
const char *ks;
|
336
336
|
int obj_type = T_NONE;
|
337
337
|
const char *json_class_name = 0;
|
338
|
+
Mode mode = pi->options->mode;
|
338
339
|
|
339
340
|
pi->s++;
|
340
341
|
next_non_white(pi);
|
@@ -361,7 +362,7 @@ read_obj(ParseInfo pi) {
|
|
361
362
|
} else {
|
362
363
|
ks = 0;
|
363
364
|
}
|
364
|
-
if (0 != ks && Qundef == obj && ObjectMode ==
|
365
|
+
if (0 != ks && Qundef == obj && ObjectMode == mode) {
|
365
366
|
if ('^' == *ks && '\0' == ks[2]) { // special directions
|
366
367
|
switch (ks[1]) {
|
367
368
|
case 't': // Time
|
@@ -390,19 +391,6 @@ read_obj(ParseInfo pi) {
|
|
390
391
|
obj_type = T_STRUCT;
|
391
392
|
key = Qundef;
|
392
393
|
break;
|
393
|
-
/*
|
394
|
-
case 'r': // Id for circular reference
|
395
|
-
val = read_next(pi, T_FIXNUM);
|
396
|
-
if (T_FIXNUM == rb_type(val)) {
|
397
|
-
obj_type = T_FIXNUM;
|
398
|
-
obj = circ_array_get(pi->circ_array, NUM2ULONG(val));
|
399
|
-
if (Qundef == obj || Qnil == obj) {
|
400
|
-
raise_error("Failed to find referenced object", pi->str, pi->s);
|
401
|
-
}
|
402
|
-
key = Qundef;
|
403
|
-
}
|
404
|
-
break;
|
405
|
-
*/
|
406
394
|
default:
|
407
395
|
// handle later
|
408
396
|
break;
|
@@ -417,7 +405,7 @@ read_obj(ParseInfo pi) {
|
|
417
405
|
obj = rb_hash_new();
|
418
406
|
obj_type = T_HASH;
|
419
407
|
}
|
420
|
-
if (ObjectMode ==
|
408
|
+
if (ObjectMode == mode && 0 != ks && '^' == *ks) {
|
421
409
|
int val_type = rb_type(val);
|
422
410
|
|
423
411
|
if ('i' == ks[1] && '\0' == ks[2] && T_FIXNUM == val_type) {
|
@@ -457,7 +445,7 @@ read_obj(ParseInfo pi) {
|
|
457
445
|
} else {
|
458
446
|
rb_hash_aset(obj, key, val);
|
459
447
|
}
|
460
|
-
if ((CompatMode ==
|
448
|
+
if ((CompatMode == mode || ObjectMode == mode) &&
|
461
449
|
0 == json_class_name &&
|
462
450
|
0 != ks && 'j' == *ks && 0 == strcmp("json_class", ks) &&
|
463
451
|
T_STRING == rb_type(val)) {
|
data/ext/oj/oj.c
CHANGED
@@ -239,11 +239,10 @@ parse_options(VALUE ropts, Options copts) {
|
|
239
239
|
}
|
240
240
|
for (o = ynos; 0 != o->attr; o++) {
|
241
241
|
if (Qnil != (v = rb_hash_lookup(ropts, o->sym))) {
|
242
|
-
VALUE c = rb_obj_class(v);
|
243
242
|
|
244
|
-
if (
|
243
|
+
if (Qtrue == v) {
|
245
244
|
*o->attr = Yes;
|
246
|
-
} else if (
|
245
|
+
} else if (Qfalse == v) {
|
247
246
|
*o->attr = No;
|
248
247
|
} else {
|
249
248
|
rb_raise(rb_eArgError, "%s must be true or false.\n", StringValuePtr(o->sym));
|
data/lib/oj/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
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-03-
|
12
|
+
date: 2012-03-16 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'The fastest JSON parser and object serializer. '
|
15
15
|
email: peter@ohler.com
|