json_pure 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -2
- data/LICENSE +56 -0
- data/README.md +1 -1
- data/Rakefile +9 -4
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +95 -40
- data/ext/json/ext/parser/parser.c +20 -15
- data/ext/json/ext/parser/parser.rl +12 -7
- data/java/src/json/ext/Generator.java +33 -10
- data/json-java.gemspec +1 -2
- data/json.gemspec +0 -0
- data/json_pure.gemspec +5 -5
- data/lib/json/add/bigdecimal.rb +2 -2
- data/lib/json/add/complex.rb +2 -2
- data/lib/json/add/rational.rb +2 -2
- data/lib/json/add/regexp.rb +2 -2
- data/lib/json/common.rb +2 -2
- data/lib/json/pure/generator.rb +2 -1
- data/lib/json/pure/parser.rb +9 -1
- data/lib/json/version.rb +1 -1
- data/tests/json_common_interface_test.rb +4 -4
- data/tests/json_generator_test.rb +44 -0
- data/tests/json_parser_test.rb +14 -14
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fab9422e98859d78988b32e0b4bd32de3f12265967d142a623853a90a7640b29
|
4
|
+
data.tar.gz: b8d15790e812a4e3a22bab7c935c9a3e70a4ad303e61e949a229773f51c357b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90bc0dd8e8ed6a061f201483568751ca2b4e6ab020d1cfe398c9f28fafc973d8715f3f798c36d064e3cadb7da14216855ea7e6c57b9d635cb8c4ac6006e2b817
|
7
|
+
data.tar.gz: 8a20ce759eaafdb7f933c1d4265144785fc212e27dc50ab0bb25b5d0337c11807e1c3f2107e2ccfa4a4b117714f3737c199904ce28ca993ff4284d8ebb38ad0d
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -4,7 +4,6 @@ language: ruby
|
|
4
4
|
|
5
5
|
# Specify which ruby versions you wish to run your tests on, each version will be used
|
6
6
|
rvm:
|
7
|
-
- 1.9.3
|
8
7
|
- 2.0.0
|
9
8
|
- 2.1
|
10
9
|
- 2.2
|
@@ -12,12 +11,14 @@ rvm:
|
|
12
11
|
- 2.4
|
13
12
|
- 2.5
|
14
13
|
- 2.6
|
14
|
+
- 2.7.0-preview3
|
15
15
|
- ruby-head
|
16
16
|
- jruby
|
17
|
+
- jruby-9.2.7.0
|
17
18
|
matrix:
|
18
19
|
allow_failures:
|
19
|
-
- rvm: 1.9.3
|
20
20
|
- rvm: ruby-head
|
21
21
|
- rvm: jruby
|
22
|
+
- rvm: jruby-9.2.7.0
|
22
23
|
script: "bundle exec rake"
|
23
24
|
sudo: false
|
data/LICENSE
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a) place your modifications in the Public Domain or otherwise
|
13
|
+
make them Freely Available, such as by posting said
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
15
|
+
the author to include your modifications in the software.
|
16
|
+
|
17
|
+
b) use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c) give non-standard binaries non-standard names, with
|
21
|
+
instructions on where to get the original software distribution.
|
22
|
+
|
23
|
+
d) make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or binary form,
|
26
|
+
provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a) distribute the binaries and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent)
|
30
|
+
on where to get the original distribution.
|
31
|
+
|
32
|
+
b) accompany the distribution with the machine-readable source of
|
33
|
+
the software.
|
34
|
+
|
35
|
+
c) give non-standard binaries non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d) make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under these terms.
|
43
|
+
|
44
|
+
For the list of those files and their copying conditions, see the
|
45
|
+
file LEGAL.
|
46
|
+
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
48
|
+
output from the software do not automatically fall under the
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
51
|
+
software.
|
52
|
+
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
56
|
+
PURPOSE.
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -23,8 +23,13 @@ class UndocumentedTestTask < Rake::TestTask
|
|
23
23
|
def desc(*) end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
which = lambda { |c|
|
27
|
+
w = `which #{c}`
|
28
|
+
break w.chomp unless w.empty?
|
29
|
+
}
|
30
|
+
|
31
|
+
MAKE = ENV['MAKE'] || %w[gmake make].find(&which)
|
32
|
+
BUNDLE = ENV['BUNDLE'] || %w[bundle].find(&which)
|
28
33
|
PKG_NAME = 'json'
|
29
34
|
PKG_TITLE = 'JSON Implementation for Ruby'
|
30
35
|
PKG_VERSION = File.read('VERSION').chomp
|
@@ -47,8 +52,8 @@ JAVA_CLASSES = []
|
|
47
52
|
JRUBY_PARSER_JAR = File.expand_path("lib/json/ext/parser.jar")
|
48
53
|
JRUBY_GENERATOR_JAR = File.expand_path("lib/json/ext/generator.jar")
|
49
54
|
|
50
|
-
RAGEL_CODEGEN = %w[rlcodegen rlgen-cd ragel].find
|
51
|
-
RAGEL_DOTGEN = %w[rlgen-dot rlgen-cd ragel].find
|
55
|
+
RAGEL_CODEGEN = %w[rlcodegen rlgen-cd ragel].find(&which)
|
56
|
+
RAGEL_DOTGEN = %w[rlgen-dot rlgen-cd ragel].find(&which)
|
52
57
|
|
53
58
|
desc "Installing library (pure)"
|
54
59
|
task :install_pure => :version do
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.0
|
@@ -15,7 +15,7 @@ static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
|
|
15
15
|
#endif
|
16
16
|
mFloat, mString, mString_Extend,
|
17
17
|
mTrueClass, mFalseClass, mNilClass, eGeneratorError,
|
18
|
-
eNestingError,
|
18
|
+
eNestingError,
|
19
19
|
i_SAFE_STATE_PROTOTYPE;
|
20
20
|
|
21
21
|
static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before,
|
@@ -237,6 +237,7 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
|
|
237
237
|
int escape_len;
|
238
238
|
unsigned char c;
|
239
239
|
char buf[6] = { '\\', 'u' };
|
240
|
+
int ascii_only = rb_enc_str_asciionly_p(string);
|
240
241
|
|
241
242
|
for (start = 0, end = 0; end < len;) {
|
242
243
|
p = ptr + end;
|
@@ -281,14 +282,17 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
|
|
281
282
|
break;
|
282
283
|
default:
|
283
284
|
{
|
284
|
-
unsigned short clen =
|
285
|
-
if (
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
285
|
+
unsigned short clen = 1;
|
286
|
+
if (!ascii_only) {
|
287
|
+
clen += trailingBytesForUTF8[c];
|
288
|
+
if (end + clen > len) {
|
289
|
+
rb_raise(rb_path2class("JSON::GeneratorError"),
|
290
|
+
"partial character in source, but hit end");
|
291
|
+
}
|
292
|
+
if (!isLegalUTF8((UTF8 *) p, clen)) {
|
293
|
+
rb_raise(rb_path2class("JSON::GeneratorError"),
|
294
|
+
"source sequence is illegal/malformed utf-8");
|
295
|
+
}
|
292
296
|
}
|
293
297
|
end += clen;
|
294
298
|
}
|
@@ -692,7 +696,7 @@ static VALUE cState_aref(VALUE self, VALUE name)
|
|
692
696
|
if (RTEST(rb_funcall(self, i_respond_to_p, 1, name))) {
|
693
697
|
return rb_funcall(self, i_send, 1, name);
|
694
698
|
} else {
|
695
|
-
return
|
699
|
+
return rb_attr_get(self, rb_intern_str(rb_str_concat(rb_str_new2("@"), name)));
|
696
700
|
}
|
697
701
|
}
|
698
702
|
|
@@ -715,43 +719,83 @@ static VALUE cState_aset(VALUE self, VALUE name, VALUE value)
|
|
715
719
|
return Qnil;
|
716
720
|
}
|
717
721
|
|
718
|
-
|
722
|
+
struct hash_foreach_arg {
|
723
|
+
FBuffer *buffer;
|
724
|
+
JSON_Generator_State *state;
|
725
|
+
VALUE Vstate;
|
726
|
+
int iter;
|
727
|
+
};
|
728
|
+
|
729
|
+
static int
|
730
|
+
json_object_i(VALUE key, VALUE val, VALUE _arg)
|
719
731
|
{
|
732
|
+
struct hash_foreach_arg *arg = (struct hash_foreach_arg *)_arg;
|
733
|
+
FBuffer *buffer = arg->buffer;
|
734
|
+
JSON_Generator_State *state = arg->state;
|
735
|
+
VALUE Vstate = arg->Vstate;
|
736
|
+
|
720
737
|
char *object_nl = state->object_nl;
|
721
738
|
long object_nl_len = state->object_nl_len;
|
722
739
|
char *indent = state->indent;
|
723
740
|
long indent_len = state->indent_len;
|
724
|
-
long max_nesting = state->max_nesting;
|
725
741
|
char *delim = FBUFFER_PTR(state->object_delim);
|
726
742
|
long delim_len = FBUFFER_LEN(state->object_delim);
|
727
743
|
char *delim2 = FBUFFER_PTR(state->object_delim2);
|
728
744
|
long delim2_len = FBUFFER_LEN(state->object_delim2);
|
745
|
+
long depth = state->depth;
|
746
|
+
int j;
|
747
|
+
VALUE klass, key_to_s;
|
748
|
+
|
749
|
+
if (arg->iter > 0) fbuffer_append(buffer, delim, delim_len);
|
750
|
+
if (object_nl) {
|
751
|
+
fbuffer_append(buffer, object_nl, object_nl_len);
|
752
|
+
}
|
753
|
+
if (indent) {
|
754
|
+
for (j = 0; j < depth; j++) {
|
755
|
+
fbuffer_append(buffer, indent, indent_len);
|
756
|
+
}
|
757
|
+
}
|
758
|
+
|
759
|
+
klass = CLASS_OF(key);
|
760
|
+
if (klass == rb_cString) {
|
761
|
+
key_to_s = key;
|
762
|
+
} else if (klass == rb_cSymbol) {
|
763
|
+
key_to_s = rb_id2str(SYM2ID(key));
|
764
|
+
} else {
|
765
|
+
key_to_s = rb_funcall(key, i_to_s, 0);
|
766
|
+
}
|
767
|
+
Check_Type(key_to_s, T_STRING);
|
768
|
+
generate_json(buffer, Vstate, state, key_to_s);
|
769
|
+
fbuffer_append(buffer, delim2, delim2_len);
|
770
|
+
generate_json(buffer, Vstate, state, val);
|
771
|
+
|
772
|
+
arg->iter++;
|
773
|
+
return ST_CONTINUE;
|
774
|
+
}
|
775
|
+
|
776
|
+
static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
|
777
|
+
{
|
778
|
+
char *object_nl = state->object_nl;
|
779
|
+
long object_nl_len = state->object_nl_len;
|
780
|
+
char *indent = state->indent;
|
781
|
+
long indent_len = state->indent_len;
|
782
|
+
long max_nesting = state->max_nesting;
|
729
783
|
long depth = ++state->depth;
|
730
|
-
int
|
731
|
-
|
784
|
+
int j;
|
785
|
+
struct hash_foreach_arg arg;
|
786
|
+
|
732
787
|
if (max_nesting != 0 && depth > max_nesting) {
|
733
788
|
fbuffer_free(buffer);
|
734
789
|
rb_raise(eNestingError, "nesting of %ld is too deep", --state->depth);
|
735
790
|
}
|
736
791
|
fbuffer_append_char(buffer, '{');
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
for (j = 0; j < depth; j++) {
|
745
|
-
fbuffer_append(buffer, indent, indent_len);
|
746
|
-
}
|
747
|
-
}
|
748
|
-
key = rb_ary_entry(keys, i);
|
749
|
-
key_to_s = rb_funcall(key, i_to_s, 0);
|
750
|
-
Check_Type(key_to_s, T_STRING);
|
751
|
-
generate_json(buffer, Vstate, state, key_to_s);
|
752
|
-
fbuffer_append(buffer, delim2, delim2_len);
|
753
|
-
generate_json(buffer, Vstate, state, rb_hash_aref(obj, key));
|
754
|
-
}
|
792
|
+
|
793
|
+
arg.buffer = buffer;
|
794
|
+
arg.state = state;
|
795
|
+
arg.Vstate = Vstate;
|
796
|
+
arg.iter = 0;
|
797
|
+
rb_hash_foreach(obj, json_object_i, (VALUE)&arg);
|
798
|
+
|
755
799
|
depth = --state->depth;
|
756
800
|
if (object_nl) {
|
757
801
|
fbuffer_append(buffer, object_nl, object_nl_len);
|
@@ -802,11 +846,22 @@ static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
|
|
802
846
|
fbuffer_append_char(buffer, ']');
|
803
847
|
}
|
804
848
|
|
849
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
850
|
+
static int enc_utf8_compatible_p(rb_encoding *enc)
|
851
|
+
{
|
852
|
+
if (enc == rb_usascii_encoding()) return 1;
|
853
|
+
if (enc == rb_utf8_encoding()) return 1;
|
854
|
+
return 0;
|
855
|
+
}
|
856
|
+
#endif
|
857
|
+
|
805
858
|
static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
|
806
859
|
{
|
807
860
|
fbuffer_append_char(buffer, '"');
|
808
861
|
#ifdef HAVE_RUBY_ENCODING_H
|
809
|
-
|
862
|
+
if (!enc_utf8_compatible_p(rb_enc_get(obj))) {
|
863
|
+
obj = rb_str_encode(obj, CEncoding_UTF_8, 0, Qnil);
|
864
|
+
}
|
810
865
|
#endif
|
811
866
|
if (state->ascii_only) {
|
812
867
|
convert_UTF8_to_JSON_ASCII(buffer, obj);
|
@@ -970,6 +1025,8 @@ static VALUE cState_generate(VALUE self, VALUE obj)
|
|
970
1025
|
* * *allow_nan*: true if NaN, Infinity, and -Infinity should be
|
971
1026
|
* generated, otherwise an exception is thrown, if these values are
|
972
1027
|
* encountered. This options defaults to false.
|
1028
|
+
* * *ascii_only*: true if only ASCII characters should be generated. This
|
1029
|
+
* ontions defaults to false.
|
973
1030
|
* * *buffer_initial_length*: sets the initial length of the generator's
|
974
1031
|
* internal buffer.
|
975
1032
|
*/
|
@@ -1025,10 +1082,8 @@ static VALUE cState_from_state_s(VALUE self, VALUE opts)
|
|
1025
1082
|
} else if (rb_obj_is_kind_of(opts, rb_cHash)) {
|
1026
1083
|
return rb_funcall(self, i_new, 1, opts);
|
1027
1084
|
} else {
|
1028
|
-
|
1029
|
-
|
1030
|
-
}
|
1031
|
-
return rb_funcall(CJSON_SAFE_STATE_PROTOTYPE, i_dup, 0);
|
1085
|
+
VALUE prototype = rb_const_get(mJSON, i_SAFE_STATE_PROTOTYPE);
|
1086
|
+
return rb_funcall(prototype, i_dup, 0);
|
1032
1087
|
}
|
1033
1088
|
}
|
1034
1089
|
|
@@ -1267,7 +1322,7 @@ static VALUE cState_allow_nan_p(VALUE self)
|
|
1267
1322
|
/*
|
1268
1323
|
* call-seq: ascii_only?
|
1269
1324
|
*
|
1270
|
-
* Returns true, if
|
1325
|
+
* Returns true, if only ASCII characters should be generated. Otherwise
|
1271
1326
|
* returns false.
|
1272
1327
|
*/
|
1273
1328
|
static VALUE cState_ascii_only_p(VALUE self)
|
@@ -1344,6 +1399,8 @@ void Init_generator(void)
|
|
1344
1399
|
|
1345
1400
|
eGeneratorError = rb_path2class("JSON::GeneratorError");
|
1346
1401
|
eNestingError = rb_path2class("JSON::NestingError");
|
1402
|
+
rb_gc_register_mark_object(eGeneratorError);
|
1403
|
+
rb_gc_register_mark_object(eNestingError);
|
1347
1404
|
|
1348
1405
|
cState = rb_define_class_under(mGenerator, "State", rb_cObject);
|
1349
1406
|
rb_define_alloc_func(cState, cState_s_allocate);
|
@@ -1409,7 +1466,6 @@ void Init_generator(void)
|
|
1409
1466
|
mNilClass = rb_define_module_under(mGeneratorMethods, "NilClass");
|
1410
1467
|
rb_define_method(mNilClass, "to_json", mNilClass_to_json, -1);
|
1411
1468
|
|
1412
|
-
CRegexp_MULTILINE = rb_const_get(rb_cRegexp, rb_intern("MULTILINE"));
|
1413
1469
|
i_to_s = rb_intern("to_s");
|
1414
1470
|
i_to_json = rb_intern("to_json");
|
1415
1471
|
i_new = rb_intern("new");
|
@@ -1440,5 +1496,4 @@ void Init_generator(void)
|
|
1440
1496
|
i_encode = rb_intern("encode");
|
1441
1497
|
#endif
|
1442
1498
|
i_SAFE_STATE_PROTOTYPE = rb_intern("SAFE_STATE_PROTOTYPE");
|
1443
|
-
CJSON_SAFE_STATE_PROTOTYPE = Qnil;
|
1444
1499
|
}
|
@@ -27,7 +27,7 @@ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
|
|
27
27
|
|
28
28
|
/* unicode */
|
29
29
|
|
30
|
-
static const char digit_values[256] = {
|
30
|
+
static const signed char digit_values[256] = {
|
31
31
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
32
32
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
33
33
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
|
@@ -46,7 +46,7 @@ static const char digit_values[256] = {
|
|
46
46
|
|
47
47
|
static UTF32 unescape_unicode(const unsigned char *p)
|
48
48
|
{
|
49
|
-
char b;
|
49
|
+
signed char b;
|
50
50
|
UTF32 result = 0;
|
51
51
|
b = digit_values[p[0]];
|
52
52
|
if (b < 0) return UNI_REPLACEMENT_CHAR;
|
@@ -1676,10 +1676,8 @@ case 7:
|
|
1676
1676
|
|
1677
1677
|
if (json->symbolize_names && json->parsing_name) {
|
1678
1678
|
*result = rb_str_intern(*result);
|
1679
|
-
} else {
|
1680
|
-
|
1681
|
-
rb_str_resize(*result, RSTRING_LEN(*result));
|
1682
|
-
}
|
1679
|
+
} else if (RB_TYPE_P(*result, T_STRING)) {
|
1680
|
+
rb_str_resize(*result, RSTRING_LEN(*result));
|
1683
1681
|
}
|
1684
1682
|
if (cs >= JSON_string_first_final) {
|
1685
1683
|
return p + 1;
|
@@ -1835,7 +1833,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1835
1833
|
} else {
|
1836
1834
|
json->max_nesting = 100;
|
1837
1835
|
json->allow_nan = 0;
|
1838
|
-
json->create_additions =
|
1836
|
+
json->create_additions = 0;
|
1839
1837
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
1840
1838
|
json->object_class = Qnil;
|
1841
1839
|
json->array_class = Qnil;
|
@@ -1850,7 +1848,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
1850
1848
|
}
|
1851
1849
|
|
1852
1850
|
|
1853
|
-
#line
|
1851
|
+
#line 1852 "parser.c"
|
1854
1852
|
enum {JSON_start = 1};
|
1855
1853
|
enum {JSON_first_final = 10};
|
1856
1854
|
enum {JSON_error = 0};
|
@@ -1858,7 +1856,7 @@ enum {JSON_error = 0};
|
|
1858
1856
|
enum {JSON_en_main = 1};
|
1859
1857
|
|
1860
1858
|
|
1861
|
-
#line
|
1859
|
+
#line 760 "parser.rl"
|
1862
1860
|
|
1863
1861
|
|
1864
1862
|
/*
|
@@ -1875,16 +1873,16 @@ static VALUE cParser_parse(VALUE self)
|
|
1875
1873
|
GET_PARSER;
|
1876
1874
|
|
1877
1875
|
|
1878
|
-
#line
|
1876
|
+
#line 1877 "parser.c"
|
1879
1877
|
{
|
1880
1878
|
cs = JSON_start;
|
1881
1879
|
}
|
1882
1880
|
|
1883
|
-
#line
|
1881
|
+
#line 776 "parser.rl"
|
1884
1882
|
p = json->source;
|
1885
1883
|
pe = p + json->len;
|
1886
1884
|
|
1887
|
-
#line
|
1885
|
+
#line 1886 "parser.c"
|
1888
1886
|
{
|
1889
1887
|
if ( p == pe )
|
1890
1888
|
goto _test_eof;
|
@@ -1918,7 +1916,7 @@ st0:
|
|
1918
1916
|
cs = 0;
|
1919
1917
|
goto _out;
|
1920
1918
|
tr2:
|
1921
|
-
#line
|
1919
|
+
#line 752 "parser.rl"
|
1922
1920
|
{
|
1923
1921
|
char *np = JSON_parse_value(json, p, pe, &result, 0);
|
1924
1922
|
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
|
@@ -1928,7 +1926,7 @@ st10:
|
|
1928
1926
|
if ( ++p == pe )
|
1929
1927
|
goto _test_eof10;
|
1930
1928
|
case 10:
|
1931
|
-
#line
|
1929
|
+
#line 1930 "parser.c"
|
1932
1930
|
switch( (*p) ) {
|
1933
1931
|
case 13: goto st10;
|
1934
1932
|
case 32: goto st10;
|
@@ -2017,7 +2015,7 @@ case 9:
|
|
2017
2015
|
_out: {}
|
2018
2016
|
}
|
2019
2017
|
|
2020
|
-
#line
|
2018
|
+
#line 779 "parser.rl"
|
2021
2019
|
|
2022
2020
|
if (cs >= JSON_first_final && p == pe) {
|
2023
2021
|
return result;
|
@@ -2091,14 +2089,21 @@ void Init_parser(void)
|
|
2091
2089
|
cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
|
2092
2090
|
eParserError = rb_path2class("JSON::ParserError");
|
2093
2091
|
eNestingError = rb_path2class("JSON::NestingError");
|
2092
|
+
rb_gc_register_mark_object(eParserError);
|
2093
|
+
rb_gc_register_mark_object(eNestingError);
|
2094
2094
|
rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
|
2095
2095
|
rb_define_method(cParser, "initialize", cParser_initialize, -1);
|
2096
2096
|
rb_define_method(cParser, "parse", cParser_parse, 0);
|
2097
2097
|
rb_define_method(cParser, "source", cParser_source, 0);
|
2098
2098
|
|
2099
2099
|
CNaN = rb_const_get(mJSON, rb_intern("NaN"));
|
2100
|
+
rb_gc_register_mark_object(CNaN);
|
2101
|
+
|
2100
2102
|
CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
|
2103
|
+
rb_gc_register_mark_object(CInfinity);
|
2104
|
+
|
2101
2105
|
CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
|
2106
|
+
rb_gc_register_mark_object(CMinusInfinity);
|
2102
2107
|
|
2103
2108
|
i_json_creatable_p = rb_intern("json_creatable?");
|
2104
2109
|
i_json_create = rb_intern("json_create");
|
@@ -25,7 +25,7 @@ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
|
|
25
25
|
|
26
26
|
/* unicode */
|
27
27
|
|
28
|
-
static const char digit_values[256] = {
|
28
|
+
static const signed char digit_values[256] = {
|
29
29
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
30
30
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
31
31
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
|
@@ -44,7 +44,7 @@ static const char digit_values[256] = {
|
|
44
44
|
|
45
45
|
static UTF32 unescape_unicode(const unsigned char *p)
|
46
46
|
{
|
47
|
-
char b;
|
47
|
+
signed char b;
|
48
48
|
UTF32 result = 0;
|
49
49
|
b = digit_values[p[0]];
|
50
50
|
if (b < 0) return UNI_REPLACEMENT_CHAR;
|
@@ -571,10 +571,8 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
571
571
|
|
572
572
|
if (json->symbolize_names && json->parsing_name) {
|
573
573
|
*result = rb_str_intern(*result);
|
574
|
-
} else {
|
575
|
-
|
576
|
-
rb_str_resize(*result, RSTRING_LEN(*result));
|
577
|
-
}
|
574
|
+
} else if (RB_TYPE_P(*result, T_STRING)) {
|
575
|
+
rb_str_resize(*result, RSTRING_LEN(*result));
|
578
576
|
}
|
579
577
|
if (cs >= JSON_string_first_final) {
|
580
578
|
return p + 1;
|
@@ -730,7 +728,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
730
728
|
} else {
|
731
729
|
json->max_nesting = 100;
|
732
730
|
json->allow_nan = 0;
|
733
|
-
json->create_additions =
|
731
|
+
json->create_additions = 0;
|
734
732
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
735
733
|
json->object_class = Qnil;
|
736
734
|
json->array_class = Qnil;
|
@@ -851,14 +849,21 @@ void Init_parser(void)
|
|
851
849
|
cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
|
852
850
|
eParserError = rb_path2class("JSON::ParserError");
|
853
851
|
eNestingError = rb_path2class("JSON::NestingError");
|
852
|
+
rb_gc_register_mark_object(eParserError);
|
853
|
+
rb_gc_register_mark_object(eNestingError);
|
854
854
|
rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
|
855
855
|
rb_define_method(cParser, "initialize", cParser_initialize, -1);
|
856
856
|
rb_define_method(cParser, "parse", cParser_parse, 0);
|
857
857
|
rb_define_method(cParser, "source", cParser_source, 0);
|
858
858
|
|
859
859
|
CNaN = rb_const_get(mJSON, rb_intern("NaN"));
|
860
|
+
rb_gc_register_mark_object(CNaN);
|
861
|
+
|
860
862
|
CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
|
863
|
+
rb_gc_register_mark_object(CInfinity);
|
864
|
+
|
861
865
|
CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
|
866
|
+
rb_gc_register_mark_object(CMinusInfinity);
|
862
867
|
|
863
868
|
i_json_creatable_p = rb_intern("json_creatable?");
|
864
869
|
i_json_create = rb_intern("json_create");
|
@@ -7,6 +7,7 @@ package json.ext;
|
|
7
7
|
|
8
8
|
import org.jruby.Ruby;
|
9
9
|
import org.jruby.RubyArray;
|
10
|
+
import org.jruby.RubyBasicObject;
|
10
11
|
import org.jruby.RubyBignum;
|
11
12
|
import org.jruby.RubyBoolean;
|
12
13
|
import org.jruby.RubyClass;
|
@@ -15,6 +16,7 @@ import org.jruby.RubyFloat;
|
|
15
16
|
import org.jruby.RubyHash;
|
16
17
|
import org.jruby.RubyNumeric;
|
17
18
|
import org.jruby.RubyString;
|
19
|
+
import org.jruby.runtime.ClassIndex;
|
18
20
|
import org.jruby.runtime.ThreadContext;
|
19
21
|
import org.jruby.runtime.builtin.IRubyObject;
|
20
22
|
import org.jruby.util.ByteList;
|
@@ -57,6 +59,19 @@ public final class Generator {
|
|
57
59
|
return handler.generateNew(session, object);
|
58
60
|
}
|
59
61
|
|
62
|
+
// NOTE: drop this once Ruby 1.9.3 support is gone!
|
63
|
+
private static final int FIXNUM = 1;
|
64
|
+
private static final int BIGNUM = 2;
|
65
|
+
private static final int ARRAY = 3;
|
66
|
+
private static final int STRING = 4;
|
67
|
+
private static final int NIL = 5;
|
68
|
+
private static final int TRUE = 6;
|
69
|
+
private static final int FALSE = 7;
|
70
|
+
private static final int HASH = 10;
|
71
|
+
private static final int FLOAT = 11;
|
72
|
+
// hard-coded due JRuby 1.7 compatibility
|
73
|
+
// https://github.com/jruby/jruby/blob/1.7.27/core/src/main/java/org/jruby/runtime/ClassIndex.java
|
74
|
+
|
60
75
|
/**
|
61
76
|
* Returns the best serialization handler for the given object.
|
62
77
|
*/
|
@@ -65,16 +80,24 @@ public final class Generator {
|
|
65
80
|
@SuppressWarnings("unchecked")
|
66
81
|
private static <T extends IRubyObject>
|
67
82
|
Handler<? super T> getHandlerFor(Ruby runtime, T object) {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
83
|
+
switch (((RubyBasicObject) object).getNativeTypeIndex()) {
|
84
|
+
// can not use getNativeClassIndex due 1.7 compatibility
|
85
|
+
case NIL : return (Handler) NIL_HANDLER;
|
86
|
+
case TRUE : return (Handler) TRUE_HANDLER;
|
87
|
+
case FALSE : return (Handler) FALSE_HANDLER;
|
88
|
+
case FLOAT : return (Handler) FLOAT_HANDLER;
|
89
|
+
case FIXNUM : return (Handler) FIXNUM_HANDLER;
|
90
|
+
case BIGNUM : return (Handler) BIGNUM_HANDLER;
|
91
|
+
case STRING :
|
92
|
+
if (((RubyBasicObject) object).getMetaClass() != runtime.getString()) break;
|
93
|
+
return (Handler) STRING_HANDLER;
|
94
|
+
case ARRAY :
|
95
|
+
if (((RubyBasicObject) object).getMetaClass() != runtime.getArray()) break;
|
96
|
+
return (Handler) ARRAY_HANDLER;
|
97
|
+
case HASH :
|
98
|
+
if (((RubyBasicObject) object).getMetaClass() != runtime.getHash()) break;
|
99
|
+
return (Handler) HASH_HANDLER;
|
100
|
+
}
|
78
101
|
return GENERIC_HANDLER;
|
79
102
|
}
|
80
103
|
|
data/json-java.gemspec
CHANGED
@@ -8,9 +8,8 @@ spec = Gem::Specification.new do |s|
|
|
8
8
|
s.description = "A JSON implementation as a JRuby extension."
|
9
9
|
s.author = "Daniel Luz"
|
10
10
|
s.email = "dev+ruby@mernen.com"
|
11
|
-
s.homepage = "http://
|
11
|
+
s.homepage = "http://flori.github.com/json"
|
12
12
|
s.platform = 'java'
|
13
|
-
s.rubyforge_project = "json-jruby"
|
14
13
|
s.licenses = ["Ruby"]
|
15
14
|
|
16
15
|
s.files = Dir["{docs,lib,tests}/**/*"]
|
data/json.gemspec
CHANGED
Binary file
|
data/json_pure.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: json_pure 2.
|
2
|
+
# stub: json_pure 2.3.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "json_pure".freeze
|
6
|
-
s.version = "2.
|
6
|
+
s.version = "2.3.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "2019-
|
11
|
+
s.date = "2019-12-11"
|
12
12
|
s.description = "This is a JSON implementation in pure Ruby.".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.extra_rdoc_files = ["README.md".freeze]
|
15
|
-
s.files = ["./tests/test_helper.rb".freeze, ".gitignore".freeze, ".travis.yml".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "README-json-jruby.md".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "
|
15
|
+
s.files = ["./tests/test_helper.rb".freeze, ".gitignore".freeze, ".travis.yml".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README-json-jruby.md".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "diagrams/.keep".freeze, "ext/json/ext/fbuffer/fbuffer.h".freeze, "ext/json/ext/generator/depend".freeze, "ext/json/ext/generator/extconf.rb".freeze, "ext/json/ext/generator/generator.c".freeze, "ext/json/ext/generator/generator.h".freeze, "ext/json/ext/parser/depend".freeze, "ext/json/ext/parser/extconf.rb".freeze, "ext/json/ext/parser/parser.c".freeze, "ext/json/ext/parser/parser.h".freeze, "ext/json/ext/parser/parser.rl".freeze, "ext/json/extconf.rb".freeze, "install.rb".freeze, "java/src/json/ext/ByteListTranscoder.java".freeze, "java/src/json/ext/Generator.java".freeze, "java/src/json/ext/GeneratorMethods.java".freeze, "java/src/json/ext/GeneratorService.java".freeze, "java/src/json/ext/GeneratorState.java".freeze, "java/src/json/ext/OptionsReader.java".freeze, "java/src/json/ext/Parser.java".freeze, "java/src/json/ext/Parser.rl".freeze, "java/src/json/ext/ParserService.java".freeze, "java/src/json/ext/RuntimeInfo.java".freeze, "java/src/json/ext/StringDecoder.java".freeze, "java/src/json/ext/StringEncoder.java".freeze, "java/src/json/ext/Utils.java".freeze, "json-java.gemspec".freeze, "json.gemspec".freeze, "json_pure.gemspec".freeze, "lib/json.rb".freeze, "lib/json/add/bigdecimal.rb".freeze, "lib/json/add/complex.rb".freeze, "lib/json/add/core.rb".freeze, "lib/json/add/date.rb".freeze, "lib/json/add/date_time.rb".freeze, "lib/json/add/exception.rb".freeze, "lib/json/add/ostruct.rb".freeze, "lib/json/add/range.rb".freeze, "lib/json/add/rational.rb".freeze, "lib/json/add/regexp.rb".freeze, "lib/json/add/set.rb".freeze, "lib/json/add/struct.rb".freeze, "lib/json/add/symbol.rb".freeze, "lib/json/add/time.rb".freeze, "lib/json/common.rb".freeze, "lib/json/ext.rb".freeze, "lib/json/ext/.keep".freeze, "lib/json/generic_object.rb".freeze, "lib/json/pure.rb".freeze, "lib/json/pure/generator.rb".freeze, "lib/json/pure/parser.rb".freeze, "lib/json/version.rb".freeze, "references/rfc7159.txt".freeze, "tests/fixtures/fail10.json".freeze, "tests/fixtures/fail11.json".freeze, "tests/fixtures/fail12.json".freeze, "tests/fixtures/fail13.json".freeze, "tests/fixtures/fail14.json".freeze, "tests/fixtures/fail18.json".freeze, "tests/fixtures/fail19.json".freeze, "tests/fixtures/fail2.json".freeze, "tests/fixtures/fail20.json".freeze, "tests/fixtures/fail21.json".freeze, "tests/fixtures/fail22.json".freeze, "tests/fixtures/fail23.json".freeze, "tests/fixtures/fail24.json".freeze, "tests/fixtures/fail25.json".freeze, "tests/fixtures/fail27.json".freeze, "tests/fixtures/fail28.json".freeze, "tests/fixtures/fail3.json".freeze, "tests/fixtures/fail4.json".freeze, "tests/fixtures/fail5.json".freeze, "tests/fixtures/fail6.json".freeze, "tests/fixtures/fail7.json".freeze, "tests/fixtures/fail8.json".freeze, "tests/fixtures/fail9.json".freeze, "tests/fixtures/obsolete_fail1.json".freeze, "tests/fixtures/pass1.json".freeze, "tests/fixtures/pass15.json".freeze, "tests/fixtures/pass16.json".freeze, "tests/fixtures/pass17.json".freeze, "tests/fixtures/pass2.json".freeze, "tests/fixtures/pass26.json".freeze, "tests/fixtures/pass3.json".freeze, "tests/json_addition_test.rb".freeze, "tests/json_common_interface_test.rb".freeze, "tests/json_encoding_test.rb".freeze, "tests/json_ext_parser_test.rb".freeze, "tests/json_fixtures_test.rb".freeze, "tests/json_generator_test.rb".freeze, "tests/json_generic_object_test.rb".freeze, "tests/json_parser_test.rb".freeze, "tests/json_string_matching_test.rb".freeze, "tests/test_helper.rb".freeze, "tools/diff.sh".freeze, "tools/fuzz.rb".freeze, "tools/server.rb".freeze]
|
16
16
|
s.homepage = "http://flori.github.com/json".freeze
|
17
17
|
s.licenses = ["Ruby".freeze]
|
18
18
|
s.rdoc_options = ["--title".freeze, "JSON implemention for ruby".freeze, "--main".freeze, "README.md".freeze]
|
19
19
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9".freeze)
|
20
|
-
s.rubygems_version = "
|
20
|
+
s.rubygems_version = "3.0.3".freeze
|
21
21
|
s.summary = "JSON Implementation for Ruby".freeze
|
22
22
|
s.test_files = ["./tests/test_helper.rb".freeze]
|
23
23
|
|
data/lib/json/add/bigdecimal.rb
CHANGED
data/lib/json/add/complex.rb
CHANGED
data/lib/json/add/rational.rb
CHANGED
data/lib/json/add/regexp.rb
CHANGED
data/lib/json/common.rb
CHANGED
@@ -153,7 +153,7 @@ module JSON
|
|
153
153
|
# * *object_class*: Defaults to Hash
|
154
154
|
# * *array_class*: Defaults to Array
|
155
155
|
def parse(source, opts = {})
|
156
|
-
Parser.new(source, opts).parse
|
156
|
+
Parser.new(source, **(opts||{})).parse
|
157
157
|
end
|
158
158
|
|
159
159
|
# Parse the JSON document _source_ into a Ruby data structure and return it.
|
@@ -176,7 +176,7 @@ module JSON
|
|
176
176
|
:max_nesting => false,
|
177
177
|
:allow_nan => true
|
178
178
|
}.merge(opts)
|
179
|
-
Parser.new(source, opts).parse
|
179
|
+
Parser.new(source, **(opts||{})).parse
|
180
180
|
end
|
181
181
|
|
182
182
|
# Generate a JSON document from the Ruby data structure _obj_ and return
|
data/lib/json/pure/generator.rb
CHANGED
data/lib/json/pure/parser.rb
CHANGED
@@ -197,7 +197,15 @@ module JSON
|
|
197
197
|
def parse_value
|
198
198
|
case
|
199
199
|
when scan(FLOAT)
|
200
|
-
|
200
|
+
if @decimal_class then
|
201
|
+
if @decimal_class == BigDecimal then
|
202
|
+
BigDecimal(self[1])
|
203
|
+
else
|
204
|
+
@decimal_class.new(self[1]) || Float(self[1])
|
205
|
+
end
|
206
|
+
else
|
207
|
+
Float(self[1])
|
208
|
+
end
|
201
209
|
when scan(INTEGER)
|
202
210
|
Integer(self[1])
|
203
211
|
when scan(TRUE)
|
data/lib/json/version.rb
CHANGED
@@ -27,15 +27,15 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_parser
|
30
|
-
assert_match
|
30
|
+
assert_match(/::Parser\z/, JSON.parser.name)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_generator
|
34
|
-
assert_match
|
34
|
+
assert_match(/::Generator\z/, JSON.generator.name)
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_state
|
38
|
-
assert_match
|
38
|
+
assert_match(/::Generator::State\z/, JSON.state.name)
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_create_id
|
@@ -56,7 +56,7 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_parse_bang
|
59
|
-
assert_equal [ 1,
|
59
|
+
assert_equal [ 1, Infinity, 3, ], JSON.parse!('[ 1, Infinity, 3 ]')
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_generate
|
@@ -40,6 +40,44 @@ class JSONGeneratorTest < Test::Unit::TestCase
|
|
40
40
|
EOT
|
41
41
|
end
|
42
42
|
|
43
|
+
def silence
|
44
|
+
v = $VERBOSE
|
45
|
+
$VERBOSE = nil
|
46
|
+
yield
|
47
|
+
ensure
|
48
|
+
$VERBOSE = v
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_remove_const_segv
|
52
|
+
return if RUBY_ENGINE == 'jruby'
|
53
|
+
stress = GC.stress
|
54
|
+
const = JSON::SAFE_STATE_PROTOTYPE.dup
|
55
|
+
|
56
|
+
bignum_too_long_to_embed_as_string = 1234567890123456789012345
|
57
|
+
expect = bignum_too_long_to_embed_as_string.to_s
|
58
|
+
GC.stress = true
|
59
|
+
|
60
|
+
10.times do |i|
|
61
|
+
tmp = bignum_too_long_to_embed_as_string.to_json
|
62
|
+
raise "'\#{expect}' is expected, but '\#{tmp}'" unless tmp == expect
|
63
|
+
end
|
64
|
+
|
65
|
+
silence do
|
66
|
+
JSON.const_set :SAFE_STATE_PROTOTYPE, nil
|
67
|
+
end
|
68
|
+
|
69
|
+
10.times do |i|
|
70
|
+
assert_raise TypeError do
|
71
|
+
bignum_too_long_to_embed_as_string.to_json
|
72
|
+
end
|
73
|
+
end
|
74
|
+
ensure
|
75
|
+
GC.stress = stress
|
76
|
+
silence do
|
77
|
+
JSON.const_set :SAFE_STATE_PROTOTYPE, const
|
78
|
+
end
|
79
|
+
end if JSON.const_defined?("Ext")
|
80
|
+
|
43
81
|
def test_generate
|
44
82
|
json = generate(@hash)
|
45
83
|
assert_equal(parse(@json2), parse(json))
|
@@ -374,4 +412,10 @@ EOT
|
|
374
412
|
assert_equal '["foo"]', JSON.generate([s.new('foo')])
|
375
413
|
end
|
376
414
|
end
|
415
|
+
|
416
|
+
if defined?(Encoding)
|
417
|
+
def test_nonutf8_encoding
|
418
|
+
assert_equal("\"5\u{b0}\"", "5\xb0".force_encoding("iso-8859-1").to_json)
|
419
|
+
end
|
420
|
+
end
|
377
421
|
end
|
data/tests/json_parser_test.rb
CHANGED
@@ -91,27 +91,27 @@ class JSONParserTest < Test::Unit::TestCase
|
|
91
91
|
assert_raise(JSON::ParserError) { parse('+23') }
|
92
92
|
assert_raise(JSON::ParserError) { parse('.23') }
|
93
93
|
assert_raise(JSON::ParserError) { parse('023') }
|
94
|
-
assert_equal
|
95
|
-
assert_equal
|
96
|
-
assert_equal_float
|
97
|
-
assert_equal_float
|
98
|
-
assert_equal_float
|
99
|
-
assert_equal_float
|
100
|
-
assert_equal_float
|
101
|
-
assert_equal_float
|
102
|
-
assert_equal_float
|
103
|
-
assert_equal_float
|
94
|
+
assert_equal(23, parse('23'))
|
95
|
+
assert_equal(-23, parse('-23'))
|
96
|
+
assert_equal_float(3.141, parse('3.141'))
|
97
|
+
assert_equal_float(-3.141, parse('-3.141'))
|
98
|
+
assert_equal_float(3.141, parse('3141e-3'))
|
99
|
+
assert_equal_float(3.141, parse('3141.1e-3'))
|
100
|
+
assert_equal_float(3.141, parse('3141E-3'))
|
101
|
+
assert_equal_float(3.141, parse('3141.0E-3'))
|
102
|
+
assert_equal_float(-3.141, parse('-3141.0e-3'))
|
103
|
+
assert_equal_float(-3.141, parse('-3141e-3'))
|
104
104
|
assert_raise(ParserError) { parse('NaN') }
|
105
105
|
assert parse('NaN', :allow_nan => true).nan?
|
106
106
|
assert_raise(ParserError) { parse('Infinity') }
|
107
|
-
assert_equal
|
107
|
+
assert_equal(1.0/0, parse('Infinity', :allow_nan => true))
|
108
108
|
assert_raise(ParserError) { parse('-Infinity') }
|
109
|
-
assert_equal
|
109
|
+
assert_equal(-1.0/0, parse('-Infinity', :allow_nan => true))
|
110
110
|
end
|
111
111
|
|
112
112
|
def test_parse_bigdecimals
|
113
|
-
assert_equal(BigDecimal,
|
114
|
-
assert_equal(BigDecimal
|
113
|
+
assert_equal(BigDecimal, JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"].class)
|
114
|
+
assert_equal(BigDecimal("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] )
|
115
115
|
end
|
116
116
|
|
117
117
|
if Array.method_defined?(:permutation)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_pure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- ".travis.yml"
|
51
51
|
- CHANGES.md
|
52
52
|
- Gemfile
|
53
|
+
- LICENSE
|
53
54
|
- README-json-jruby.md
|
54
55
|
- README.md
|
55
56
|
- Rakefile
|
@@ -174,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
175
|
- !ruby/object:Gem::Version
|
175
176
|
version: '0'
|
176
177
|
requirements: []
|
177
|
-
rubygems_version: 3.
|
178
|
+
rubygems_version: 3.1.2
|
178
179
|
signing_key:
|
179
180
|
specification_version: 4
|
180
181
|
summary: JSON Implementation for Ruby
|