json_pure 1.8.3 → 1.8.5
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 +5 -13
- data/CHANGES +2 -1
- data/Gemfile +1 -4
- data/{README.rdoc → README.md} +30 -41
- data/Rakefile +7 -6
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +38 -4
- data/ext/json/ext/generator/generator.h +7 -0
- data/ext/json/ext/parser/parser.c +166 -142
- data/ext/json/ext/parser/parser.rl +52 -28
- data/java/src/json/ext/Generator.java +8 -5
- data/json-java.gemspec +15 -0
- data/json.gemspec +0 -0
- data/json_pure.gemspec +23 -23
- data/lib/json/pure/generator.rb +10 -2
- data/lib/json/version.rb +1 -1
- data/tests/test_json.rb +0 -34
- data/tests/test_json_generate.rb +11 -0
- data/tools/diff.sh +18 -0
- metadata +14 -13
@@ -1,6 +1,28 @@
|
|
1
1
|
#include "../fbuffer/fbuffer.h"
|
2
2
|
#include "parser.h"
|
3
3
|
|
4
|
+
#if defined HAVE_RUBY_ENCODING_H
|
5
|
+
# define EXC_ENCODING UTF_8,
|
6
|
+
# ifndef HAVE_RB_ENC_RAISE
|
7
|
+
static void
|
8
|
+
enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
|
9
|
+
{
|
10
|
+
va_list args;
|
11
|
+
VALUE mesg;
|
12
|
+
|
13
|
+
va_start(args, fmt);
|
14
|
+
mesg = rb_enc_vsprintf(enc, fmt, args);
|
15
|
+
va_end(args);
|
16
|
+
|
17
|
+
rb_exc_raise(rb_exc_new3(exc, mesg));
|
18
|
+
}
|
19
|
+
# define rb_enc_raise enc_raise
|
20
|
+
# endif
|
21
|
+
#else
|
22
|
+
# define EXC_ENCODING /* nothing */
|
23
|
+
# define rb_enc_raise rb_raise
|
24
|
+
#endif
|
25
|
+
|
4
26
|
/* unicode */
|
5
27
|
|
6
28
|
static const char digit_values[256] = {
|
@@ -66,9 +88,7 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
|
|
66
88
|
}
|
67
89
|
|
68
90
|
#ifdef HAVE_RUBY_ENCODING_H
|
69
|
-
static
|
70
|
-
CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
|
71
|
-
static ID i_encoding, i_encode;
|
91
|
+
static rb_encoding *UTF_8, *UTF_16BE, *UTF_16LE, *UTF_32BE, *UTF_32LE;
|
72
92
|
#else
|
73
93
|
static ID i_iconv;
|
74
94
|
#endif
|
@@ -206,14 +226,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
206
226
|
if (json->allow_nan) {
|
207
227
|
*result = CNaN;
|
208
228
|
} else {
|
209
|
-
|
229
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
|
210
230
|
}
|
211
231
|
}
|
212
232
|
action parse_infinity {
|
213
233
|
if (json->allow_nan) {
|
214
234
|
*result = CInfinity;
|
215
235
|
} else {
|
216
|
-
|
236
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
|
217
237
|
}
|
218
238
|
}
|
219
239
|
action parse_string {
|
@@ -229,7 +249,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
229
249
|
fexec p + 10;
|
230
250
|
fhold; fbreak;
|
231
251
|
} else {
|
232
|
-
|
252
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
233
253
|
}
|
234
254
|
}
|
235
255
|
np = JSON_parse_float(json, fpc, pe, result);
|
@@ -396,7 +416,7 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
396
416
|
if(cs >= JSON_array_first_final) {
|
397
417
|
return p + 1;
|
398
418
|
} else {
|
399
|
-
|
419
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
400
420
|
return NULL;
|
401
421
|
}
|
402
422
|
}
|
@@ -550,29 +570,29 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
550
570
|
|
551
571
|
static VALUE convert_encoding(VALUE source)
|
552
572
|
{
|
553
|
-
char *ptr = RSTRING_PTR(source);
|
573
|
+
const char *ptr = RSTRING_PTR(source);
|
554
574
|
long len = RSTRING_LEN(source);
|
555
575
|
if (len < 2) {
|
556
576
|
rb_raise(eParserError, "A JSON text must at least contain two octets!");
|
557
577
|
}
|
558
578
|
#ifdef HAVE_RUBY_ENCODING_H
|
559
579
|
{
|
560
|
-
|
561
|
-
if (
|
580
|
+
rb_encoding *enc = rb_enc_get(source);
|
581
|
+
if (enc == rb_ascii8bit_encoding()) {
|
562
582
|
if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
|
563
|
-
source =
|
583
|
+
source = rb_str_conv_enc(source, UTF_32BE, rb_utf8_encoding());
|
564
584
|
} else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
|
565
|
-
source =
|
585
|
+
source = rb_str_conv_enc(source, UTF_16BE, rb_utf8_encoding());
|
566
586
|
} else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
|
567
|
-
source =
|
587
|
+
source = rb_str_conv_enc(source, UTF_32LE, rb_utf8_encoding());
|
568
588
|
} else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
|
569
|
-
source =
|
589
|
+
source = rb_str_conv_enc(source, UTF_16LE, rb_utf8_encoding());
|
570
590
|
} else {
|
571
591
|
source = rb_str_dup(source);
|
572
592
|
FORCE_UTF8(source);
|
573
593
|
}
|
574
594
|
} else {
|
575
|
-
source =
|
595
|
+
source = rb_str_conv_enc(source, rb_enc_get(source), rb_utf8_encoding());
|
576
596
|
}
|
577
597
|
}
|
578
598
|
#else
|
@@ -623,12 +643,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
623
643
|
if (json->Vsource) {
|
624
644
|
rb_raise(rb_eTypeError, "already initialized instance");
|
625
645
|
}
|
646
|
+
#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
647
|
+
rb_scan_args(argc, argv, "1:", &source, &opts);
|
648
|
+
#else
|
626
649
|
rb_scan_args(argc, argv, "11", &source, &opts);
|
650
|
+
#endif
|
627
651
|
if (!NIL_P(opts)) {
|
652
|
+
#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
628
653
|
opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
|
629
654
|
if (NIL_P(opts)) {
|
630
655
|
rb_raise(rb_eArgError, "opts needs to be like a hash");
|
631
656
|
} else {
|
657
|
+
#endif
|
632
658
|
VALUE tmp = ID2SYM(i_max_nesting);
|
633
659
|
if (option_given_p(opts, tmp)) {
|
634
660
|
VALUE max_nesting = rb_hash_aref(opts, tmp);
|
@@ -691,7 +717,9 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
691
717
|
} else {
|
692
718
|
json->match_string = Qnil;
|
693
719
|
}
|
720
|
+
#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
|
694
721
|
}
|
722
|
+
#endif
|
695
723
|
} else {
|
696
724
|
json->max_nesting = 100;
|
697
725
|
json->allow_nan = 0;
|
@@ -700,12 +728,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
700
728
|
json->object_class = Qnil;
|
701
729
|
json->array_class = Qnil;
|
702
730
|
}
|
703
|
-
|
731
|
+
StringValue(source);
|
704
732
|
if (!json->quirks_mode) {
|
705
|
-
|
733
|
+
source = convert_encoding(source);
|
706
734
|
}
|
707
735
|
json->current_nesting = 0;
|
708
|
-
StringValue(source);
|
709
736
|
json->len = RSTRING_LEN(source);
|
710
737
|
json->source = RSTRING_PTR(source);;
|
711
738
|
json->Vsource = source;
|
@@ -754,7 +781,7 @@ static VALUE cParser_parse_strict(VALUE self)
|
|
754
781
|
if (cs >= JSON_first_final && p == pe) {
|
755
782
|
return result;
|
756
783
|
} else {
|
757
|
-
|
784
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
758
785
|
return Qnil;
|
759
786
|
}
|
760
787
|
}
|
@@ -792,7 +819,7 @@ static VALUE cParser_parse_quirks_mode(VALUE self)
|
|
792
819
|
if (cs >= JSON_quirks_mode_first_final && p == pe) {
|
793
820
|
return result;
|
794
821
|
} else {
|
795
|
-
|
822
|
+
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
|
796
823
|
return Qnil;
|
797
824
|
}
|
798
825
|
}
|
@@ -917,14 +944,11 @@ void Init_parser(void)
|
|
917
944
|
i_aref = rb_intern("[]");
|
918
945
|
i_leftshift = rb_intern("<<");
|
919
946
|
#ifdef HAVE_RUBY_ENCODING_H
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
|
926
|
-
i_encoding = rb_intern("encoding");
|
927
|
-
i_encode = rb_intern("encode");
|
947
|
+
UTF_8 = rb_utf8_encoding();
|
948
|
+
UTF_16BE = rb_enc_find("utf-16be");
|
949
|
+
UTF_16LE = rb_enc_find("utf-16le");
|
950
|
+
UTF_32BE = rb_enc_find("utf-32be");
|
951
|
+
UTF_32LE = rb_enc_find("utf-32le");
|
928
952
|
#else
|
929
953
|
i_iconv = rb_intern("iconv");
|
930
954
|
#endif
|
@@ -427,11 +427,14 @@ public final class Generator {
|
|
427
427
|
new Handler<IRubyObject>() {
|
428
428
|
@Override
|
429
429
|
RubyString generateNew(Session session, IRubyObject object) {
|
430
|
-
|
431
|
-
object.callMethod(session.getContext(), "to_json",
|
432
|
-
|
433
|
-
|
434
|
-
|
430
|
+
if (object.respondsTo("to_json")) {
|
431
|
+
IRubyObject result = object.callMethod(session.getContext(), "to_json",
|
432
|
+
new IRubyObject[] {session.getState()});
|
433
|
+
if (result instanceof RubyString) return (RubyString)result;
|
434
|
+
throw session.getRuntime().newTypeError("to_json must return a String");
|
435
|
+
} else {
|
436
|
+
return OBJECT_HANDLER.generateNew(session, object);
|
437
|
+
}
|
435
438
|
}
|
436
439
|
|
437
440
|
@Override
|
data/json-java.gemspec
CHANGED
@@ -14,6 +14,21 @@ spec = Gem::Specification.new do |s|
|
|
14
14
|
s.licenses = ["Ruby"]
|
15
15
|
|
16
16
|
s.files = Dir["{docs,lib,tests}/**/*"]
|
17
|
+
|
18
|
+
if s.respond_to? :specification_version then
|
19
|
+
s.specification_version = 4
|
20
|
+
|
21
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
22
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
23
|
+
s.add_development_dependency(%q<test-unit>, ["~> 2.0"])
|
24
|
+
else
|
25
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
26
|
+
s.add_dependency(%q<test-unit>, ["~> 2.0"])
|
27
|
+
end
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
30
|
+
s.add_dependency(%q<test-unit>, ["~> 2.0"])
|
31
|
+
end
|
17
32
|
end
|
18
33
|
|
19
34
|
if $0 == __FILE__
|
data/json.gemspec
CHANGED
Binary file
|
data/json_pure.gemspec
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: json_pure 1.8.
|
2
|
+
# stub: json_pure 1.8.5 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name = "json_pure"
|
6
|
-
s.version = "1.8.
|
5
|
+
s.name = "json_pure".freeze
|
6
|
+
s.version = "1.8.5"
|
7
7
|
|
8
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
|
-
s.require_paths = ["lib"]
|
10
|
-
s.authors = ["Florian Frank"]
|
11
|
-
s.date = "
|
12
|
-
s.description = "This is a JSON implementation in pure Ruby."
|
13
|
-
s.email = "flori@ping.de"
|
14
|
-
s.extra_rdoc_files = ["README.
|
15
|
-
s.files = ["./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", ".gitignore", ".travis.yml", "CHANGES", "Gemfile", "README-json-jruby.markdown", "README.
|
16
|
-
s.homepage = "http://flori.github.com/json"
|
17
|
-
s.licenses = ["Ruby"]
|
18
|
-
s.rdoc_options = ["--title", "JSON implemention for
|
19
|
-
s.rubygems_version = "2.
|
20
|
-
s.summary = "JSON Implementation for Ruby"
|
21
|
-
s.test_files = ["./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"]
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib".freeze]
|
10
|
+
s.authors = ["Florian Frank".freeze]
|
11
|
+
s.date = "2017-01-12"
|
12
|
+
s.description = "This is a JSON implementation in pure Ruby.".freeze
|
13
|
+
s.email = "flori@ping.de".freeze
|
14
|
+
s.extra_rdoc_files = ["README.md".freeze]
|
15
|
+
s.files = ["./tests/test_json.rb".freeze, "./tests/test_json_addition.rb".freeze, "./tests/test_json_encoding.rb".freeze, "./tests/test_json_fixtures.rb".freeze, "./tests/test_json_generate.rb".freeze, "./tests/test_json_generic_object.rb".freeze, "./tests/test_json_string_matching.rb".freeze, "./tests/test_json_unicode.rb".freeze, ".gitignore".freeze, ".travis.yml".freeze, "CHANGES".freeze, "Gemfile".freeze, "README-json-jruby.markdown".freeze, "README.md".freeze, "Rakefile".freeze, "TODO".freeze, "VERSION".freeze, "data/example.json".freeze, "data/index.html".freeze, "data/prototype.js".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/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, "tests/fixtures/fail1.json".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/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/setup_variant.rb".freeze, "tests/test_json.rb".freeze, "tests/test_json_addition.rb".freeze, "tests/test_json_encoding.rb".freeze, "tests/test_json_fixtures.rb".freeze, "tests/test_json_generate.rb".freeze, "tests/test_json_generic_object.rb".freeze, "tests/test_json_string_matching.rb".freeze, "tests/test_json_unicode.rb".freeze, "tools/diff.sh".freeze, "tools/fuzz.rb".freeze, "tools/server.rb".freeze]
|
16
|
+
s.homepage = "http://flori.github.com/json".freeze
|
17
|
+
s.licenses = ["Ruby".freeze]
|
18
|
+
s.rdoc_options = ["--title".freeze, "JSON implemention for Ruby".freeze, "--main".freeze, "README.md".freeze]
|
19
|
+
s.rubygems_version = "2.6.8".freeze
|
20
|
+
s.summary = "JSON Implementation for Ruby".freeze
|
21
|
+
s.test_files = ["./tests/test_json.rb".freeze, "./tests/test_json_addition.rb".freeze, "./tests/test_json_encoding.rb".freeze, "./tests/test_json_fixtures.rb".freeze, "./tests/test_json_generate.rb".freeze, "./tests/test_json_generic_object.rb".freeze, "./tests/test_json_string_matching.rb".freeze, "./tests/test_json_unicode.rb".freeze]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
24
|
s.specification_version = 4
|
25
25
|
|
26
26
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
|
-
s.add_development_dependency(%q<
|
28
|
-
s.add_development_dependency(%q<
|
27
|
+
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
28
|
+
s.add_development_dependency(%q<test-unit>.freeze, ["~> 2.0"])
|
29
29
|
else
|
30
|
-
s.add_dependency(%q<
|
31
|
-
s.add_dependency(%q<
|
30
|
+
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
31
|
+
s.add_dependency(%q<test-unit>.freeze, ["~> 2.0"])
|
32
32
|
end
|
33
33
|
else
|
34
|
-
s.add_dependency(%q<
|
35
|
-
s.add_dependency(%q<
|
34
|
+
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
35
|
+
s.add_dependency(%q<test-unit>.freeze, ["~> 2.0"])
|
36
36
|
end
|
37
37
|
end
|
data/lib/json/pure/generator.rb
CHANGED
@@ -363,7 +363,11 @@ module JSON
|
|
363
363
|
result << state.space_before
|
364
364
|
result << ':'
|
365
365
|
result << state.space
|
366
|
-
|
366
|
+
if value.respond_to?(:to_json)
|
367
|
+
result << value.to_json(state)
|
368
|
+
else
|
369
|
+
result << %{"#{String(value)}"}
|
370
|
+
end
|
367
371
|
first = false
|
368
372
|
}
|
369
373
|
depth = state.depth -= 1
|
@@ -398,7 +402,11 @@ module JSON
|
|
398
402
|
each { |value|
|
399
403
|
result << delim unless first
|
400
404
|
result << state.indent * depth if indent
|
401
|
-
|
405
|
+
if value.respond_to?(:to_json)
|
406
|
+
result << value.to_json(state)
|
407
|
+
else
|
408
|
+
result << %{"#{String(value)}"}
|
409
|
+
end
|
402
410
|
first = false
|
403
411
|
}
|
404
412
|
depth = state.depth -= 1
|
data/lib/json/version.rb
CHANGED
data/tests/test_json.rb
CHANGED
@@ -7,20 +7,6 @@ require 'stringio'
|
|
7
7
|
require 'tempfile'
|
8
8
|
require 'ostruct'
|
9
9
|
|
10
|
-
unless Array.method_defined?(:permutation)
|
11
|
-
begin
|
12
|
-
require 'enumerator'
|
13
|
-
require 'permutation'
|
14
|
-
class Array
|
15
|
-
def permutation
|
16
|
-
Permutation.for(self).to_enum.map { |x| x.project }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
rescue LoadError
|
20
|
-
warn "Skipping permutation tests."
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
10
|
class TestJSON < Test::Unit::TestCase
|
25
11
|
include JSON
|
26
12
|
|
@@ -146,26 +132,6 @@ class TestJSON < Test::Unit::TestCase
|
|
146
132
|
assert_raise(JSON::ParserError) { JSON.parse('[ 1, ]', :quirks_mode => true) }
|
147
133
|
end
|
148
134
|
|
149
|
-
if Array.method_defined?(:permutation)
|
150
|
-
def test_parse_more_complex_arrays
|
151
|
-
a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
|
152
|
-
a.permutation.each do |perm|
|
153
|
-
json = pretty_generate(perm)
|
154
|
-
assert_equal perm, parse(json)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_parse_complex_objects
|
159
|
-
a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
|
160
|
-
a.permutation.each do |perm|
|
161
|
-
s = "a"
|
162
|
-
orig_obj = perm.inject({}) { |h, x| h[s.dup] = x; s = s.succ; h }
|
163
|
-
json = pretty_generate(orig_obj)
|
164
|
-
assert_equal orig_obj, parse(json)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
135
|
def test_parse_arrays
|
170
136
|
assert_equal([1,2,3], parse('[1,2,3]'))
|
171
137
|
assert_equal([1.2,2,3], parse('[1.2,2,3]'))
|
data/tests/test_json_generate.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
|
+
# frozen_string_literal: false
|
3
4
|
|
4
5
|
require 'test/unit'
|
5
6
|
require File.join(File.dirname(__FILE__), 'setup_variant')
|
@@ -334,4 +335,14 @@ EOT
|
|
334
335
|
assert_equal true, JSON.generate(["\xea"])
|
335
336
|
end
|
336
337
|
end
|
338
|
+
|
339
|
+
def test_string_subclass
|
340
|
+
s = Class.new(String) do
|
341
|
+
def to_s; self; end
|
342
|
+
undef to_json
|
343
|
+
end
|
344
|
+
assert_nothing_raised(SystemStackError) do
|
345
|
+
assert_equal '["foo"]', JSON.generate([s.new('foo')])
|
346
|
+
end
|
347
|
+
end
|
337
348
|
end
|
data/tools/diff.sh
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
files=`find ext -name '*.[ch]' -o -name parser.rl`
|
4
|
+
|
5
|
+
for f in $files
|
6
|
+
do
|
7
|
+
b=`basename $f`
|
8
|
+
g=`find ../ruby/ext/json -name $b`
|
9
|
+
d=`diff -u $f $g`
|
10
|
+
test -z "$d" && continue
|
11
|
+
echo "$d"
|
12
|
+
read -p "Edit diff of $b? " a
|
13
|
+
case $a in
|
14
|
+
[yY]*)
|
15
|
+
vimdiff $f $g
|
16
|
+
;;
|
17
|
+
esac
|
18
|
+
done
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_pure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,25 +25,25 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: test-unit
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '2.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '2.0'
|
41
41
|
description: This is a JSON implementation in pure Ruby.
|
42
42
|
email: flori@ping.de
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files:
|
46
|
-
- README.
|
46
|
+
- README.md
|
47
47
|
files:
|
48
48
|
- "./tests/test_json.rb"
|
49
49
|
- "./tests/test_json_addition.rb"
|
@@ -58,7 +58,7 @@ files:
|
|
58
58
|
- CHANGES
|
59
59
|
- Gemfile
|
60
60
|
- README-json-jruby.markdown
|
61
|
-
- README.
|
61
|
+
- README.md
|
62
62
|
- Rakefile
|
63
63
|
- TODO
|
64
64
|
- VERSION
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- tests/test_json_generic_object.rb
|
157
157
|
- tests/test_json_string_matching.rb
|
158
158
|
- tests/test_json_unicode.rb
|
159
|
+
- tools/diff.sh
|
159
160
|
- tools/fuzz.rb
|
160
161
|
- tools/server.rb
|
161
162
|
homepage: http://flori.github.com/json
|
@@ -165,9 +166,9 @@ metadata: {}
|
|
165
166
|
post_install_message:
|
166
167
|
rdoc_options:
|
167
168
|
- "--title"
|
168
|
-
- JSON implemention for
|
169
|
+
- JSON implemention for Ruby
|
169
170
|
- "--main"
|
170
|
-
- README.
|
171
|
+
- README.md
|
171
172
|
require_paths:
|
172
173
|
- lib
|
173
174
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -182,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
183
|
version: '0'
|
183
184
|
requirements: []
|
184
185
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.
|
186
|
+
rubygems_version: 2.6.8
|
186
187
|
signing_key:
|
187
188
|
specification_version: 4
|
188
189
|
summary: JSON Implementation for Ruby
|