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.
@@ -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 VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
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
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
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
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
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
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
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
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
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
- VALUE encoding = rb_funcall(source, i_encoding, 0);
561
- if (encoding == CEncoding_ASCII_8BIT) {
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 = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
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 = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
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 = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
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 = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
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 = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
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
- source = rb_convert_type(source, T_STRING, "String", "to_str");
731
+ StringValue(source);
704
732
  if (!json->quirks_mode) {
705
- source = convert_encoding(StringValue(source));
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
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
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
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
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
- CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
921
- CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
922
- CEncoding_UTF_16LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16le"));
923
- CEncoding_UTF_32BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32be"));
924
- CEncoding_UTF_32LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32le"));
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
- IRubyObject result =
431
- 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");
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
@@ -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__
Binary file
@@ -1,37 +1,37 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: json_pure 1.8.3 ruby lib
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.3"
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 = "2015-09-11"
12
- s.description = "This is a JSON implementation in pure Ruby."
13
- s.email = "flori@ping.de"
14
- s.extra_rdoc_files = ["README.rdoc"]
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.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", "ext/json/extconf.rb", "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"]
16
- s.homepage = "http://flori.github.com/json"
17
- s.licenses = ["Ruby"]
18
- s.rdoc_options = ["--title", "JSON implemention for ruby", "--main", "README.rdoc"]
19
- s.rubygems_version = "2.4.8"
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<permutation>, [">= 0"])
28
- s.add_development_dependency(%q<rake>, [">= 0"])
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<permutation>, [">= 0"])
31
- s.add_dependency(%q<rake>, [">= 0"])
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<permutation>, [">= 0"])
35
- s.add_dependency(%q<rake>, [">= 0"])
34
+ s.add_dependency(%q<rake>.freeze, [">= 0"])
35
+ s.add_dependency(%q<test-unit>.freeze, ["~> 2.0"])
36
36
  end
37
37
  end
@@ -363,7 +363,11 @@ module JSON
363
363
  result << state.space_before
364
364
  result << ':'
365
365
  result << state.space
366
- result << value.to_json(state)
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
- result << value.to_json(state)
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
@@ -1,6 +1,6 @@
1
1
  module JSON
2
2
  # JSON version
3
- VERSION = '1.8.3'
3
+ VERSION = '1.8.5'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -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]'))
@@ -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
@@ -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.3
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: 2015-09-11 00:00:00.000000000 Z
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: permutation
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: rake
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.rdoc
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.rdoc
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 ruby
169
+ - JSON implemention for Ruby
169
170
  - "--main"
170
- - README.rdoc
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.4.8
186
+ rubygems_version: 2.6.8
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: JSON Implementation for Ruby