diff options
-rw-r--r-- | Rakefile | 22 | ||||
-rw-r--r-- | ext/json/ext/parser/parser.c | 141 | ||||
-rw-r--r-- | ext/json/ext/parser/parser.rl | 1 | ||||
-rwxr-xr-x | json-java.gemspec | 6 | ||||
-rw-r--r-- | json.gemspec | 3 | ||||
-rw-r--r-- | json_pure.gemspec | 22 | ||||
-rw-r--r-- | lib/json/pure/generator.rb | 2 | ||||
-rw-r--r-- | lib/json/pure/parser.rb | 2 | ||||
-rw-r--r-- | tests/json_fixtures_test.rb | 7 |
9 files changed, 107 insertions, 99 deletions
@@ -89,7 +89,7 @@ if defined?(Gem) and defined?(Gem::PackageTask) s.require_path = 'lib' s.add_development_dependency 'rake' - s.add_development_dependency 'test-unit', '~> 2.0' + s.add_development_dependency 'test-unit', '>= 2.0', '< 4.0' s.extra_rdoc_files << 'README.md' s.rdoc_options << @@ -106,7 +106,10 @@ if defined?(Gem) and defined?(Gem::PackageTask) desc 'Creates a json_pure.gemspec file' task :gemspec_pure => :version do File.open('json_pure.gemspec', 'w') do |gemspec| - gemspec.write spec_pure.to_ruby + src = spec_pure.to_ruby + src.gsub!(/# stub:.*/, "# This gemspec is generated automatically using `rake gemspec`.\n" \ + "# Do not modify directly.") + gemspec.write src end end @@ -115,7 +118,7 @@ if defined?(Gem) and defined?(Gem::PackageTask) pkg.package_files = PKG_FILES end - desc 'Create all gemspec files' + desc 'Alias for gemspec_pure' task :gemspec => [ :gemspec_pure ] end @@ -142,7 +145,8 @@ task :check_env do end desc "Testing library (pure ruby)" -task :test_pure => [ :clean, :check_env, :do_test_pure ] +task :test_pure => [ :set_env_pure, :check_env, :do_test_pure ] +task(:set_env_pure) { ENV['JSON'] = 'pure' } UndocumentedTestTask.new do |t| t.name = 'do_test_pure' @@ -153,10 +157,7 @@ UndocumentedTestTask.new do |t| end desc "Testing library (pure ruby and extension)" -task :test do - sh "env JSON=pure #{BUNDLE} exec rake test_pure" or exit 1 - sh "env JSON=ext #{BUNDLE} exec rake test_ext" or exit 1 -end +task :test => [ :test_pure, :test_ext ] namespace :gems do desc 'Install all development gems' @@ -223,7 +224,8 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby' end desc "Testing library (jruby)" - task :test_ext => [ :check_env, :create_jar, :do_test_ext ] + task :test_ext => [ :set_env_ext, :create_jar, :check_env, :do_test_ext ] + task(:set_env_ext) { ENV['JSON'] = 'ext' } UndocumentedTestTask.new do |t| t.name = 'do_test_ext' @@ -329,6 +331,8 @@ else end src = File.read("parser.c").gsub(/[ \t]+$/, '') src.gsub!(/^static const int (JSON_.*=.*);$/, 'enum {\1};') + src.gsub!(/0 <= \(\*p\) && \(\*p\) <= 31/, "0 <= (signed char)(*p) && (*p) <= 31") + src[0, 0] = "/* This file is automatically generated from parser.rl by using ragel */" File.open("parser.c", "w") {|f| f.print src} end end diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index bc4ac46..6f0e4ac 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -1,4 +1,4 @@ - +/* This file is automatically generated from parser.rl by using ragel */ #line 1 "parser.rl" #include "../fbuffer/fbuffer.h" #include "parser.h" @@ -112,7 +112,7 @@ enum {JSON_object_error = 0}; enum {JSON_object_en_main = 1}; -#line 167 "parser.rl" +#line 168 "parser.rl" static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting) @@ -133,7 +133,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu cs = JSON_object_start; } -#line 182 "parser.rl" +#line 183 "parser.rl" #line 139 "parser.c" { @@ -163,7 +163,7 @@ case 2: goto st2; goto st0; tr2: -#line 149 "parser.rl" +#line 150 "parser.rl" { char *np; json->parsing_name = 1; @@ -251,6 +251,7 @@ tr11: p--; {p++; cs = 9; goto _out;} } else { if (NIL_P(json->object_class)) { + OBJ_FREEZE(last_name); rb_hash_aset(*result, last_name, v); } else { rb_funcall(*result, i_aset, 2, last_name, v); @@ -263,7 +264,7 @@ st9: if ( ++p == pe ) goto _test_eof9; case 9: -#line 267 "parser.c" +#line 268 "parser.c" switch( (*p) ) { case 13: goto st9; case 32: goto st9; @@ -352,14 +353,14 @@ case 18: goto st9; goto st18; tr4: -#line 157 "parser.rl" +#line 158 "parser.rl" { p--; {p++; cs = 27; goto _out;} } goto st27; st27: if ( ++p == pe ) goto _test_eof27; case 27: -#line 363 "parser.c" +#line 364 "parser.c" goto st0; st19: if ( ++p == pe ) @@ -457,7 +458,7 @@ case 26: _out: {} } -#line 183 "parser.rl" +#line 184 "parser.rl" if (cs >= JSON_object_first_final) { if (json->create_additions) { @@ -482,7 +483,7 @@ case 26: -#line 486 "parser.c" +#line 487 "parser.c" enum {JSON_value_start = 1}; enum {JSON_value_first_final = 29}; enum {JSON_value_error = 0}; @@ -490,7 +491,7 @@ enum {JSON_value_error = 0}; enum {JSON_value_en_main = 1}; -#line 283 "parser.rl" +#line 284 "parser.rl" static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting) @@ -498,14 +499,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul int cs = EVIL; -#line 502 "parser.c" +#line 503 "parser.c" { cs = JSON_value_start; } -#line 290 "parser.rl" +#line 291 "parser.rl" -#line 509 "parser.c" +#line 510 "parser.c" { if ( p == pe ) goto _test_eof; @@ -539,14 +540,14 @@ st0: cs = 0; goto _out; tr2: -#line 235 "parser.rl" +#line 236 "parser.rl" { char *np = JSON_parse_string(json, p, pe, result); if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;} } goto st29; tr3: -#line 240 "parser.rl" +#line 241 "parser.rl" { char *np; if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) { @@ -566,7 +567,7 @@ tr3: } goto st29; tr7: -#line 258 "parser.rl" +#line 259 "parser.rl" { char *np; np = JSON_parse_array(json, p, pe, result, current_nesting + 1); @@ -574,7 +575,7 @@ tr7: } goto st29; tr11: -#line 264 "parser.rl" +#line 265 "parser.rl" { char *np; np = JSON_parse_object(json, p, pe, result, current_nesting + 1); @@ -582,7 +583,7 @@ tr11: } goto st29; tr25: -#line 228 "parser.rl" +#line 229 "parser.rl" { if (json->allow_nan) { *result = CInfinity; @@ -592,7 +593,7 @@ tr25: } goto st29; tr27: -#line 221 "parser.rl" +#line 222 "parser.rl" { if (json->allow_nan) { *result = CNaN; @@ -602,19 +603,19 @@ tr27: } goto st29; tr31: -#line 215 "parser.rl" +#line 216 "parser.rl" { *result = Qfalse; } goto st29; tr34: -#line 212 "parser.rl" +#line 213 "parser.rl" { *result = Qnil; } goto st29; tr37: -#line 218 "parser.rl" +#line 219 "parser.rl" { *result = Qtrue; } @@ -623,9 +624,9 @@ st29: if ( ++p == pe ) goto _test_eof29; case 29: -#line 270 "parser.rl" +#line 271 "parser.rl" { p--; {p++; cs = 29; goto _out;} } -#line 629 "parser.c" +#line 630 "parser.c" switch( (*p) ) { case 13: goto st29; case 32: goto st29; @@ -866,7 +867,7 @@ case 28: _out: {} } -#line 291 "parser.rl" +#line 292 "parser.rl" if (cs >= JSON_value_first_final) { return p; @@ -876,7 +877,7 @@ case 28: } -#line 880 "parser.c" +#line 881 "parser.c" enum {JSON_integer_start = 1}; enum {JSON_integer_first_final = 3}; enum {JSON_integer_error = 0}; @@ -884,7 +885,7 @@ enum {JSON_integer_error = 0}; enum {JSON_integer_en_main = 1}; -#line 307 "parser.rl" +#line 308 "parser.rl" static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -892,15 +893,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res int cs = EVIL; -#line 896 "parser.c" +#line 897 "parser.c" { cs = JSON_integer_start; } -#line 314 "parser.rl" +#line 315 "parser.rl" json->memo = p; -#line 904 "parser.c" +#line 905 "parser.c" { if ( p == pe ) goto _test_eof; @@ -934,14 +935,14 @@ case 3: goto st0; goto tr4; tr4: -#line 304 "parser.rl" +#line 305 "parser.rl" { p--; {p++; cs = 4; goto _out;} } goto st4; st4: if ( ++p == pe ) goto _test_eof4; case 4: -#line 945 "parser.c" +#line 946 "parser.c" goto st0; st5: if ( ++p == pe ) @@ -960,7 +961,7 @@ case 5: _out: {} } -#line 316 "parser.rl" +#line 317 "parser.rl" if (cs >= JSON_integer_first_final) { long len = p - json->memo; @@ -975,7 +976,7 @@ case 5: } -#line 979 "parser.c" +#line 980 "parser.c" enum {JSON_float_start = 1}; enum {JSON_float_first_final = 8}; enum {JSON_float_error = 0}; @@ -983,7 +984,7 @@ enum {JSON_float_error = 0}; enum {JSON_float_en_main = 1}; -#line 341 "parser.rl" +#line 342 "parser.rl" static int is_bigdecimal_class(VALUE obj) @@ -1004,15 +1005,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul int cs = EVIL; -#line 1008 "parser.c" +#line 1009 "parser.c" { cs = JSON_float_start; } -#line 361 "parser.rl" +#line 362 "parser.rl" json->memo = p; -#line 1016 "parser.c" +#line 1017 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1070,14 +1071,14 @@ case 8: goto st0; goto tr9; tr9: -#line 335 "parser.rl" +#line 336 "parser.rl" { p--; {p++; cs = 9; goto _out;} } goto st9; st9: if ( ++p == pe ) goto _test_eof9; case 9: -#line 1081 "parser.c" +#line 1082 "parser.c" goto st0; st5: if ( ++p == pe ) @@ -1138,7 +1139,7 @@ case 7: _out: {} } -#line 363 "parser.rl" +#line 364 "parser.rl" if (cs >= JSON_float_first_final) { long len = p - json->memo; @@ -1164,7 +1165,7 @@ case 7: -#line 1168 "parser.c" +#line 1169 "parser.c" enum {JSON_array_start = 1}; enum {JSON_array_first_final = 17}; enum {JSON_array_error = 0}; @@ -1172,7 +1173,7 @@ enum {JSON_array_error = 0}; enum {JSON_array_en_main = 1}; -#line 416 "parser.rl" +#line 417 "parser.rl" static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting) @@ -1186,14 +1187,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class); -#line 1190 "parser.c" +#line 1191 "parser.c" { cs = JSON_array_start; } -#line 429 "parser.rl" +#line 430 "parser.rl" -#line 1197 "parser.c" +#line 1198 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1232,7 +1233,7 @@ case 2: goto st2; goto st0; tr2: -#line 393 "parser.rl" +#line 394 "parser.rl" { VALUE v = Qnil; char *np = JSON_parse_value(json, p, pe, &v, current_nesting); @@ -1252,7 +1253,7 @@ st3: if ( ++p == pe ) goto _test_eof3; case 3: -#line 1256 "parser.c" +#line 1257 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; @@ -1352,14 +1353,14 @@ case 12: goto st3; goto st12; tr4: -#line 408 "parser.rl" +#line 409 "parser.rl" { p--; {p++; cs = 17; goto _out;} } goto st17; st17: if ( ++p == pe ) goto _test_eof17; case 17: -#line 1363 "parser.c" +#line 1364 "parser.c" goto st0; st13: if ( ++p == pe ) @@ -1415,7 +1416,7 @@ case 16: _out: {} } -#line 430 "parser.rl" +#line 431 "parser.rl" if(cs >= JSON_array_first_final) { return p + 1; @@ -1504,7 +1505,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd) } -#line 1508 "parser.c" +#line 1509 "parser.c" enum {JSON_string_start = 1}; enum {JSON_string_first_final = 8}; enum {JSON_string_error = 0}; @@ -1512,7 +1513,7 @@ enum {JSON_string_error = 0}; enum {JSON_string_en_main = 1}; -#line 537 "parser.rl" +#line 538 "parser.rl" static int @@ -1534,15 +1535,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu *result = rb_str_buf_new(0); -#line 1538 "parser.c" +#line 1539 "parser.c" { cs = JSON_string_start; } -#line 558 "parser.rl" +#line 559 "parser.rl" json->memo = p; -#line 1546 "parser.c" +#line 1547 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1563,11 +1564,11 @@ case 2: case 34: goto tr2; case 92: goto st3; } - if ( 0 <= (*p) && (*p) <= 31 ) + if ( 0 <= (signed char)(*p) && (*p) <= 31 ) goto st0; goto st2; tr2: -#line 523 "parser.rl" +#line 524 "parser.rl" { *result = json_string_unescape(*result, json->memo + 1, p); if (NIL_P(*result)) { @@ -1578,14 +1579,14 @@ tr2: {p = (( p + 1))-1;} } } -#line 534 "parser.rl" +#line 535 "parser.rl" { p--; {p++; cs = 8; goto _out;} } goto st8; st8: if ( ++p == pe ) goto _test_eof8; case 8: -#line 1589 "parser.c" +#line 1590 "parser.c" goto st0; st3: if ( ++p == pe ) @@ -1593,7 +1594,7 @@ st3: case 3: if ( (*p) == 117 ) goto st4; - if ( 0 <= (*p) && (*p) <= 31 ) + if ( 0 <= (signed char)(*p) && (*p) <= 31 ) goto st0; goto st2; st4: @@ -1661,7 +1662,7 @@ case 7: _out: {} } -#line 560 "parser.rl" +#line 561 "parser.rl" if (json->create_additions && RTEST(match_string = json->match_string)) { VALUE klass; @@ -1848,7 +1849,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } -#line 1852 "parser.c" +#line 1853 "parser.c" enum {JSON_start = 1}; enum {JSON_first_final = 10}; enum {JSON_error = 0}; @@ -1856,7 +1857,7 @@ enum {JSON_error = 0}; enum {JSON_en_main = 1}; -#line 760 "parser.rl" +#line 761 "parser.rl" /* @@ -1873,16 +1874,16 @@ static VALUE cParser_parse(VALUE self) GET_PARSER; -#line 1877 "parser.c" +#line 1878 "parser.c" { cs = JSON_start; } -#line 776 "parser.rl" +#line 777 "parser.rl" p = json->source; pe = p + json->len; -#line 1886 "parser.c" +#line 1887 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1916,7 +1917,7 @@ st0: cs = 0; goto _out; tr2: -#line 752 "parser.rl" +#line 753 "parser.rl" { char *np = JSON_parse_value(json, p, pe, &result, 0); if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} @@ -1926,7 +1927,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1930 "parser.c" +#line 1931 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -2015,7 +2016,7 @@ case 9: _out: {} } -#line 779 "parser.rl" +#line 780 "parser.rl" if (cs >= JSON_first_final && p == pe) { return result; diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index 6b38bb2..00a35bd 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -138,6 +138,7 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, fhold; fbreak; } else { if (NIL_P(json->object_class)) { + OBJ_FREEZE(last_name); rb_hash_aset(*result, last_name, v); } else { rb_funcall(*result, i_aset, 2, last_name, v); diff --git a/json-java.gemspec b/json-java.gemspec index f3fa0c9..1bcd639 100755 --- a/json-java.gemspec +++ b/json-java.gemspec @@ -19,14 +19,14 @@ spec = Gem::Specification.new do |s| if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_development_dependency(%q<rake>, [">= 0"]) - s.add_development_dependency(%q<test-unit>, ["~> 2.0"]) + s.add_development_dependency(%q<test-unit>, [">= 2.0", "< 4.0"]) else s.add_dependency(%q<rake>, [">= 0"]) - s.add_dependency(%q<test-unit>, ["~> 2.0"]) + s.add_dependency(%q<test-unit>, [">= 2.0", "< 4.0"]) end else s.add_dependency(%q<rake>, [">= 0"]) - s.add_dependency(%q<test-unit>, ["~> 2.0"]) + s.add_dependency(%q<test-unit>, [">= 2.0", "< 4.0"]) end end diff --git a/json.gemspec b/json.gemspec index 443c324..0c72e82 100644 --- a/json.gemspec +++ b/json.gemspec @@ -131,10 +131,9 @@ Gem::Specification.new do |s| s.licenses = ["Ruby"] s.rdoc_options = ["--title", "JSON implemention for Ruby", "--main", "README.md"] s.required_ruby_version = Gem::Requirement.new(">= 2.0") - s.rubygems_version = "3.0.2" s.summary = "JSON Implementation for Ruby" s.test_files = ["tests/test_helper.rb"] s.add_development_dependency("rake", [">= 0"]) - s.add_development_dependency("test-unit", ["~> 2.0"]) + s.add_development_dependency("test-unit", [">= 2.0", "< 4.0"]) end diff --git a/json_pure.gemspec b/json_pure.gemspec index 08413d6..7b4114a 100644 --- a/json_pure.gemspec +++ b/json_pure.gemspec @@ -1,5 +1,6 @@ # -*- encoding: utf-8 -*- -# stub: json_pure 2.3.0 ruby lib +# This gemspec is generated automatically using `rake gemspec`. +# Do not modify directly. Gem::Specification.new do |s| s.name = "json_pure".freeze @@ -8,7 +9,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Florian Frank".freeze] - s.date = "2019-12-11" + s.date = "2020-06-25" s.description = "This is a JSON implementation in pure Ruby.".freeze s.email = "flori@ping.de".freeze s.extra_rdoc_files = ["README.md".freeze] @@ -16,23 +17,20 @@ Gem::Specification.new do |s| s.homepage = "http://flori.github.com/json".freeze s.licenses = ["Ruby".freeze] s.rdoc_options = ["--title".freeze, "JSON implemention for ruby".freeze, "--main".freeze, "README.md".freeze] - s.required_ruby_version = Gem::Requirement.new(">= 1.9".freeze) - s.rubygems_version = "3.0.3".freeze + s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze) + s.rubygems_version = "3.1.2".freeze s.summary = "JSON Implementation for Ruby".freeze s.test_files = ["./tests/test_helper.rb".freeze] if s.respond_to? :specification_version then s.specification_version = 4 + end - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_development_dependency(%q<rake>.freeze, [">= 0"]) - s.add_development_dependency(%q<test-unit>.freeze, ["~> 2.0"]) - else - s.add_dependency(%q<rake>.freeze, [">= 0"]) - s.add_dependency(%q<test-unit>.freeze, ["~> 2.0"]) - end + if s.respond_to? :add_runtime_dependency then + s.add_development_dependency(%q<rake>.freeze, [">= 0"]) + s.add_development_dependency(%q<test-unit>.freeze, [">= 2.0", "< 4.0"]) else s.add_dependency(%q<rake>.freeze, [">= 0"]) - s.add_dependency(%q<test-unit>.freeze, ["~> 2.0"]) + s.add_dependency(%q<test-unit>.freeze, [">= 2.0", "< 4.0"]) end end diff --git a/lib/json/pure/generator.rb b/lib/json/pure/generator.rb index a1143f8..471af63 100644 --- a/lib/json/pure/generator.rb +++ b/lib/json/pure/generator.rb @@ -405,7 +405,7 @@ module JSON end end - # Module that holds the extinding methods if, the String module is + # Module that holds the extending methods if, the String module is # included. module Extend # Raw Strings are JSON Objects (the raw bytes are stored in an diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb index 5340296..1c8f59f 100644 --- a/lib/json/pure/parser.rb +++ b/lib/json/pure/parser.rb @@ -66,7 +66,7 @@ module JSON # also the default. It's not possible to use this option in # conjunction with the *create_additions* option. # * *create_additions*: If set to true, the Parser creates - # additions when if a matching class and create_id was found. This + # additions when a matching class and create_id are found. This # option defaults to false. # * *object_class*: Defaults to Hash # * *array_class*: Defaults to Array diff --git a/tests/json_fixtures_test.rb b/tests/json_fixtures_test.rb index 01954fe..b2a1ec8 100644 --- a/tests/json_fixtures_test.rb +++ b/tests/json_fixtures_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class JSONFixturesTest < Test::Unit::TestCase def setup - fixtures = File.join(File.dirname(__FILE__), 'fixtures/{fail,pass}.json') + fixtures = File.join(File.dirname(__FILE__), 'fixtures/{fail,pass}*.json') passed, failed = Dir[fixtures].partition { |f| f['pass'] } @passed = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort @failed = failed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort @@ -29,4 +29,9 @@ class JSONFixturesTest < Test::Unit::TestCase end end end + + def test_sanity + assert(@passed.size > 5) + assert(@failed.size > 20) + end end |