From ec16880de86c5d75bb34e9947132c2f98b744d71 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 24 Apr 2016 02:21:20 +0900 Subject: Append newline at EOF --- lib/json/add/complex.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/json/add/complex.rb b/lib/json/add/complex.rb index 2723f60..3d653bb 100644 --- a/lib/json/add/complex.rb +++ b/lib/json/add/complex.rb @@ -25,4 +25,4 @@ class Complex def to_json(*) as_json.to_json end -end \ No newline at end of file +end -- cgit v1.2.1 From 0dae40da44e38f97bc028f01224401b7c07d6c6d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 24 Apr 2016 02:17:49 +0900 Subject: Remove useless methods Remove useless overriding methods, [] and []=, which are same as OpenStruct. --- lib/json/generic_object.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/json/generic_object.rb b/lib/json/generic_object.rb index 8b8fd53..3a14f0e 100644 --- a/lib/json/generic_object.rb +++ b/lib/json/generic_object.rb @@ -47,14 +47,6 @@ module JSON table end - def [](name) - table[name.to_sym] - end - - def []=(name, value) - __send__ "#{name}=", value - end - def |(other) self.class[other.to_hash.merge(to_hash)] end -- cgit v1.2.1 From 5bf9d8439841978b6dbad381fb8f62ea61887acc Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 24 Apr 2016 02:10:53 +0900 Subject: Use assert_raise consistently --- tests/json_addition_test.rb | 4 +-- tests/json_common_interface_test.rb | 4 +-- tests/json_encoding_test.rb | 2 +- tests/json_fixtures_test.rb | 2 +- tests/json_generator_test.rb | 34 ++++++++++++------------- tests/json_parser_test.rb | 50 ++++++++++++++++++------------------- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/tests/json_addition_test.rb b/tests/json_addition_test.rb index 128f34a..cb07659 100644 --- a/tests/json_addition_test.rb +++ b/tests/json_addition_test.rb @@ -108,7 +108,7 @@ class JSONAdditionTest < Test::Unit::TestCase c = C.new assert !C.json_creatable? json = generate(c) - assert_raises(ArgumentError, NameError) { parse(json, :create_additions => true) } + assert_raise(ArgumentError, NameError) { parse(json, :create_additions => true) } end def test_raw_strings @@ -147,7 +147,7 @@ class JSONAdditionTest < Test::Unit::TestCase assert_equal s, JSON(JSON(s), :create_additions => true) struct = Struct.new :foo, :bar s = struct.new 4711, 'foot' - assert_raises(JSONError) { JSON(s) } + assert_raise(JSONError) { JSON(s) } begin raise TypeError, "test me" rescue TypeError => e diff --git a/tests/json_common_interface_test.rb b/tests/json_common_interface_test.rb index 6485328..6e02310 100644 --- a/tests/json_common_interface_test.rb +++ b/tests/json_common_interface_test.rb @@ -74,8 +74,8 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]' assert_equal too_deep, dump(eval(too_deep)) assert_kind_of String, Marshal.dump(eval(too_deep)) - assert_raises(ArgumentError) { dump(eval(too_deep), 100) } - assert_raises(ArgumentError) { Marshal.dump(eval(too_deep), 100) } + assert_raise(ArgumentError) { dump(eval(too_deep), 100) } + assert_raise(ArgumentError) { Marshal.dump(eval(too_deep), 100) } assert_equal too_deep, dump(eval(too_deep), 101) assert_kind_of String, Marshal.dump(eval(too_deep), 101) output = StringIO.new diff --git a/tests/json_encoding_test.rb b/tests/json_encoding_test.rb index 86335a1..588e9a2 100644 --- a/tests/json_encoding_test.rb +++ b/tests/json_encoding_test.rb @@ -38,7 +38,7 @@ class JSONEncodingTest < Test::Unit::TestCase else # XXX checking of correct utf8 data is not as strict (yet?) without # :ascii_only - assert_raises(JSON::GeneratorError) do + assert_raise(JSON::GeneratorError) do JSON.generate(@utf_16_data, :ascii_only => true) end end diff --git a/tests/json_fixtures_test.rb b/tests/json_fixtures_test.rb index 6681b8d..0419983 100644 --- a/tests/json_fixtures_test.rb +++ b/tests/json_fixtures_test.rb @@ -22,7 +22,7 @@ class JSONFixturesTest < Test::Unit::TestCase def test_failing for name, source in @failed - assert_raises(JSON::ParserError, JSON::NestingError, + assert_raise(JSON::ParserError, JSON::NestingError, "Did not fail for fixture '#{name}': #{source.inspect}") do JSON.parse(source) end diff --git a/tests/json_generator_test.rb b/tests/json_generator_test.rb index 2bb7e15..e310373 100644 --- a/tests/json_generator_test.rb +++ b/tests/json_generator_test.rb @@ -118,12 +118,12 @@ EOT assert s[:check_circular?] h = { 1=>2 } h[3] = h - assert_raises(JSON::NestingError) { generate(h) } - assert_raises(JSON::NestingError) { generate(h, s) } + assert_raise(JSON::NestingError) { generate(h) } + assert_raise(JSON::NestingError) { generate(h, s) } s = JSON.state.new a = [ 1, 2 ] a << a - assert_raises(JSON::NestingError) { generate(a, s) } + assert_raise(JSON::NestingError) { generate(a, s) } assert s.check_circular? assert s[:check_circular?] end @@ -180,34 +180,34 @@ EOT end def test_allow_nan - assert_raises(GeneratorError) { generate([JSON::NaN]) } + assert_raise(GeneratorError) { generate([JSON::NaN]) } assert_equal '[NaN]', generate([JSON::NaN], :allow_nan => true) - assert_raises(GeneratorError) { fast_generate([JSON::NaN]) } - assert_raises(GeneratorError) { pretty_generate([JSON::NaN]) } + assert_raise(GeneratorError) { fast_generate([JSON::NaN]) } + assert_raise(GeneratorError) { pretty_generate([JSON::NaN]) } assert_equal "[\n NaN\n]", pretty_generate([JSON::NaN], :allow_nan => true) - assert_raises(GeneratorError) { generate([JSON::Infinity]) } + assert_raise(GeneratorError) { generate([JSON::Infinity]) } assert_equal '[Infinity]', generate([JSON::Infinity], :allow_nan => true) - assert_raises(GeneratorError) { fast_generate([JSON::Infinity]) } - assert_raises(GeneratorError) { pretty_generate([JSON::Infinity]) } + assert_raise(GeneratorError) { fast_generate([JSON::Infinity]) } + assert_raise(GeneratorError) { pretty_generate([JSON::Infinity]) } assert_equal "[\n Infinity\n]", pretty_generate([JSON::Infinity], :allow_nan => true) - assert_raises(GeneratorError) { generate([JSON::MinusInfinity]) } + assert_raise(GeneratorError) { generate([JSON::MinusInfinity]) } assert_equal '[-Infinity]', generate([JSON::MinusInfinity], :allow_nan => true) - assert_raises(GeneratorError) { fast_generate([JSON::MinusInfinity]) } - assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) } + assert_raise(GeneratorError) { fast_generate([JSON::MinusInfinity]) } + assert_raise(GeneratorError) { pretty_generate([JSON::MinusInfinity]) } assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true) end def test_depth ary = []; ary << ary assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth - assert_raises(JSON::NestingError) { generate(ary) } + assert_raise(JSON::NestingError) { generate(ary) } assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth - assert_raises(JSON::NestingError) { JSON.pretty_generate(ary) } + assert_raise(JSON::NestingError) { JSON.pretty_generate(ary) } assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth s = JSON.state.new assert_equal 0, s.depth - assert_raises(JSON::NestingError) { ary.to_json(s) } + assert_raise(JSON::NestingError) { ary.to_json(s) } assert_equal 100, s.depth end @@ -333,8 +333,8 @@ EOT def test_nesting too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]' too_deep_ary = eval too_deep - assert_raises(JSON::NestingError) { generate too_deep_ary } - assert_raises(JSON::NestingError) { generate too_deep_ary, :max_nesting => 100 } + assert_raise(JSON::NestingError) { generate too_deep_ary } + assert_raise(JSON::NestingError) { generate too_deep_ary, :max_nesting => 100 } ok = generate too_deep_ary, :max_nesting => 101 assert_equal too_deep, ok ok = generate too_deep_ary, :max_nesting => nil diff --git a/tests/json_parser_test.rb b/tests/json_parser_test.rb index b21e7ec..46fa47c 100644 --- a/tests/json_parser_test.rb +++ b/tests/json_parser_test.rb @@ -50,7 +50,7 @@ class JSONParserTest < Test::Unit::TestCase assert_equal({ "a" => nil }, parse('{"a":null}')) assert_equal({ "a" => false }, parse('{ "a" : false } ')) assert_equal({ "a" => false }, parse('{"a":false}')) - assert_raises(JSON::ParserError) { parse('{false}') } + assert_raise(JSON::ParserError) { parse('{false}') } assert_equal({ "a" => true }, parse('{"a":true}')) assert_equal({ "a" => true }, parse(' { "a" : true } ')) assert_equal({ "a" => -23 }, parse(' { "a" : -23 } ')) @@ -62,10 +62,10 @@ class JSONParserTest < Test::Unit::TestCase end def test_parse_numbers - assert_raises(JSON::ParserError) { parse('+23.2') } - assert_raises(JSON::ParserError) { parse('+23') } - assert_raises(JSON::ParserError) { parse('.23') } - assert_raises(JSON::ParserError) { parse('023') } + assert_raise(JSON::ParserError) { parse('+23.2') } + assert_raise(JSON::ParserError) { parse('+23') } + assert_raise(JSON::ParserError) { parse('.23') } + assert_raise(JSON::ParserError) { parse('023') } assert_equal 23, parse('23') assert_equal -23, parse('-23') assert_equal_float 3.141, parse('3.141') @@ -76,11 +76,11 @@ class JSONParserTest < Test::Unit::TestCase assert_equal_float 3.141, parse('3141.0E-3') assert_equal_float -3.141, parse('-3141.0e-3') assert_equal_float -3.141, parse('-3141e-3') - assert_raises(ParserError) { parse('NaN') } + assert_raise(ParserError) { parse('NaN') } assert parse('NaN', :allow_nan => true).nan? - assert_raises(ParserError) { parse('Infinity') } + assert_raise(ParserError) { parse('Infinity') } assert_equal 1.0/0, parse('Infinity', :allow_nan => true) - assert_raises(ParserError) { parse('-Infinity') } + assert_raise(ParserError) { parse('-Infinity') } assert_equal -1.0/0, parse('-Infinity', :allow_nan => true) end @@ -163,19 +163,19 @@ class JSONParserTest < Test::Unit::TestCase end def test_some_wrong_inputs - assert_raises(ParserError) { parse('[] bla') } - assert_raises(ParserError) { parse('[] 1') } - assert_raises(ParserError) { parse('[] []') } - assert_raises(ParserError) { parse('[] {}') } - assert_raises(ParserError) { parse('{} []') } - assert_raises(ParserError) { parse('{} {}') } - assert_raises(ParserError) { parse('[NULL]') } - assert_raises(ParserError) { parse('[FALSE]') } - assert_raises(ParserError) { parse('[TRUE]') } - assert_raises(ParserError) { parse('[07] ') } - assert_raises(ParserError) { parse('[0a]') } - assert_raises(ParserError) { parse('[1.]') } - assert_raises(ParserError) { parse(' ') } + assert_raise(ParserError) { parse('[] bla') } + assert_raise(ParserError) { parse('[] 1') } + assert_raise(ParserError) { parse('[] []') } + assert_raise(ParserError) { parse('[] {}') } + assert_raise(ParserError) { parse('{} []') } + assert_raise(ParserError) { parse('{} {}') } + assert_raise(ParserError) { parse('[NULL]') } + assert_raise(ParserError) { parse('[FALSE]') } + assert_raise(ParserError) { parse('[TRUE]') } + assert_raise(ParserError) { parse('[07] ') } + assert_raise(ParserError) { parse('[0a]') } + assert_raise(ParserError) { parse('[1.]') } + assert_raise(ParserError) { parse(' ') } end def test_symbolize_names @@ -210,7 +210,7 @@ EOT * comment */ } EOT - assert_raises(ParserError) { parse(json) } + assert_raise(ParserError) { parse(json) } json = < 100 } + assert_raise(JSON::NestingError) { parse too_deep } + assert_raise(JSON::NestingError) { parse too_deep, :max_nesting => 100 } ok = parse too_deep, :max_nesting => 101 assert_equal too_deep_ary, ok ok = parse too_deep, :max_nesting => nil -- cgit v1.2.1 From d1389fa3c173fcb934bf0dc1f0a51083ae9e782f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 24 Apr 2016 01:52:15 +0900 Subject: Use enum Use `enum` instead of `static const int` to get rid of unused-const-variable warnings. --- Rakefile | 1 + ext/json/ext/parser/parser.c | 56 ++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Rakefile b/Rakefile index 4aa311e..4448d2e 100644 --- a/Rakefile +++ b/Rakefile @@ -361,6 +361,7 @@ else sh "ragel -x parser.rl | #{RAGEL_CODEGEN} -G2" end src = File.read("parser.c").gsub(/[ \t]+$/, '') + src.gsub!(/^static const int (JSON_.*=.*);$/, 'enum {\1};') 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 c63a462..35014b0 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -89,11 +89,11 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, #line 92 "parser.c" -static const int JSON_object_start = 1; -static const int JSON_object_first_final = 27; -static const int JSON_object_error = 0; +enum {JSON_object_start = 1}; +enum {JSON_object_first_final = 27}; +enum {JSON_object_error = 0}; -static const int JSON_object_en_main = 1; +enum {JSON_object_en_main = 1}; #line 151 "parser.rl" @@ -467,11 +467,11 @@ case 26: #line 470 "parser.c" -static const int JSON_value_start = 1; -static const int JSON_value_first_final = 29; -static const int JSON_value_error = 0; +enum {JSON_value_start = 1}; +enum {JSON_value_first_final = 29}; +enum {JSON_value_error = 0}; -static const int JSON_value_en_main = 1; +enum {JSON_value_en_main = 1}; #line 271 "parser.rl" @@ -865,11 +865,11 @@ case 28: #line 868 "parser.c" -static const int JSON_integer_start = 1; -static const int JSON_integer_first_final = 3; -static const int JSON_integer_error = 0; +enum {JSON_integer_start = 1}; +enum {JSON_integer_first_final = 3}; +enum {JSON_integer_error = 0}; -static const int JSON_integer_en_main = 1; +enum {JSON_integer_en_main = 1}; #line 295 "parser.rl" @@ -964,11 +964,11 @@ case 5: #line 967 "parser.c" -static const int JSON_float_start = 1; -static const int JSON_float_first_final = 8; -static const int JSON_float_error = 0; +enum {JSON_float_start = 1}; +enum {JSON_float_first_final = 8}; +enum {JSON_float_error = 0}; -static const int JSON_float_en_main = 1; +enum {JSON_float_en_main = 1}; #line 329 "parser.rl" @@ -1130,11 +1130,11 @@ case 7: #line 1133 "parser.c" -static const int JSON_array_start = 1; -static const int JSON_array_first_final = 17; -static const int JSON_array_error = 0; +enum {JSON_array_start = 1}; +enum {JSON_array_first_final = 17}; +enum {JSON_array_error = 0}; -static const int JSON_array_en_main = 1; +enum {JSON_array_en_main = 1}; #line 381 "parser.rl" @@ -1462,11 +1462,11 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd) #line 1465 "parser.c" -static const int JSON_string_start = 1; -static const int JSON_string_first_final = 8; -static const int JSON_string_error = 0; +enum {JSON_string_start = 1}; +enum {JSON_string_first_final = 8}; +enum {JSON_string_error = 0}; -static const int JSON_string_en_main = 1; +enum {JSON_string_en_main = 1}; #line 494 "parser.rl" @@ -1785,11 +1785,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) #line 1788 "parser.c" -static const int JSON_start = 1; -static const int JSON_first_final = 10; -static const int JSON_error = 0; +enum {JSON_start = 1}; +enum {JSON_first_final = 10}; +enum {JSON_error = 0}; -static const int JSON_en_main = 1; +enum {JSON_en_main = 1}; #line 696 "parser.rl" -- cgit v1.2.1 From d69a661d217a4174538c11f7616472649429b92a Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 24 Apr 2016 01:37:39 +0900 Subject: Remove unnecessary conversion StringValue does the conversion. --- ext/json/ext/parser/parser.c | 17 ++++++++--------- ext/json/ext/parser/parser.rl | 1 - 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index 35014b0..e933e4f 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -1773,7 +1773,6 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) json->object_class = Qnil; json->array_class = Qnil; } - source = rb_convert_type(source, T_STRING, "String", "to_str"); source = convert_encoding(StringValue(source)); json->current_nesting = 0; StringValue(source); @@ -1784,7 +1783,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } -#line 1788 "parser.c" +#line 1787 "parser.c" enum {JSON_start = 1}; enum {JSON_first_final = 10}; enum {JSON_error = 0}; @@ -1792,7 +1791,7 @@ enum {JSON_error = 0}; enum {JSON_en_main = 1}; -#line 696 "parser.rl" +#line 695 "parser.rl" /* @@ -1809,16 +1808,16 @@ static VALUE cParser_parse(VALUE self) GET_PARSER; -#line 1813 "parser.c" +#line 1812 "parser.c" { cs = JSON_start; } -#line 712 "parser.rl" +#line 711 "parser.rl" p = json->source; pe = p + json->len; -#line 1822 "parser.c" +#line 1821 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1852,7 +1851,7 @@ st0: cs = 0; goto _out; tr2: -#line 688 "parser.rl" +#line 687 "parser.rl" { char *np = JSON_parse_value(json, p, pe, &result); if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} @@ -1862,7 +1861,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1866 "parser.c" +#line 1865 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -1951,7 +1950,7 @@ case 9: _out: {} } -#line 715 "parser.rl" +#line 714 "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 6f73307..b6ab64a 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -668,7 +668,6 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) json->object_class = Qnil; json->array_class = Qnil; } - source = rb_convert_type(source, T_STRING, "String", "to_str"); source = convert_encoding(StringValue(source)); json->current_nesting = 0; StringValue(source); -- cgit v1.2.1 From b94f1aa5d1708168ed2acdea0ee01269290666c5 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 24 Apr 2016 01:47:49 +0900 Subject: Use rb_encoding Use rb_encoding functions to convert encodings. --- ext/json/ext/parser/parser.c | 162 +++++++++++++++++++----------------------- ext/json/ext/parser/parser.rl | 16 +---- 2 files changed, 75 insertions(+), 103 deletions(-) diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index e933e4f..4bbd30c 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -67,14 +67,6 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch) return len; } -#ifdef HAVE_RUBY_ENCODING_H -static VALUE CEncoding_UTF_8; - -static ID i_encode; -#else -static ID i_iconv; -#endif - static VALUE mJSON, mExt, cParser, eParserError, eNestingError; static VALUE CNaN, CInfinity, CMinusInfinity; @@ -84,11 +76,11 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, i_match_string, i_aset, i_aref, i_leftshift; -#line 110 "parser.rl" +#line 102 "parser.rl" -#line 92 "parser.c" +#line 84 "parser.c" enum {JSON_object_start = 1}; enum {JSON_object_first_final = 27}; enum {JSON_object_error = 0}; @@ -96,7 +88,7 @@ enum {JSON_object_error = 0}; enum {JSON_object_en_main = 1}; -#line 151 "parser.rl" +#line 143 "parser.rl" static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -112,14 +104,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class); -#line 116 "parser.c" +#line 108 "parser.c" { cs = JSON_object_start; } -#line 166 "parser.rl" +#line 158 "parser.rl" -#line 123 "parser.c" +#line 115 "parser.c" { if ( p == pe ) goto _test_eof; @@ -147,7 +139,7 @@ case 2: goto st2; goto st0; tr2: -#line 133 "parser.rl" +#line 125 "parser.rl" { char *np; json->parsing_name = 1; @@ -160,7 +152,7 @@ st3: if ( ++p == pe ) goto _test_eof3; case 3: -#line 164 "parser.c" +#line 156 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; @@ -227,7 +219,7 @@ case 8: goto st8; goto st0; tr11: -#line 118 "parser.rl" +#line 110 "parser.rl" { VALUE v = Qnil; char *np = JSON_parse_value(json, p, pe, &v); @@ -247,7 +239,7 @@ st9: if ( ++p == pe ) goto _test_eof9; case 9: -#line 251 "parser.c" +#line 243 "parser.c" switch( (*p) ) { case 13: goto st9; case 32: goto st9; @@ -336,14 +328,14 @@ case 18: goto st9; goto st18; tr4: -#line 141 "parser.rl" +#line 133 "parser.rl" { p--; {p++; cs = 27; goto _out;} } goto st27; st27: if ( ++p == pe ) goto _test_eof27; case 27: -#line 347 "parser.c" +#line 339 "parser.c" goto st0; st19: if ( ++p == pe ) @@ -441,7 +433,7 @@ case 26: _out: {} } -#line 167 "parser.rl" +#line 159 "parser.rl" if (cs >= JSON_object_first_final) { if (json->create_additions) { @@ -466,7 +458,7 @@ case 26: -#line 470 "parser.c" +#line 462 "parser.c" enum {JSON_value_start = 1}; enum {JSON_value_first_final = 29}; enum {JSON_value_error = 0}; @@ -474,7 +466,7 @@ enum {JSON_value_error = 0}; enum {JSON_value_en_main = 1}; -#line 271 "parser.rl" +#line 263 "parser.rl" static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -482,14 +474,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul int cs = EVIL; -#line 486 "parser.c" +#line 478 "parser.c" { cs = JSON_value_start; } -#line 278 "parser.rl" +#line 270 "parser.rl" -#line 493 "parser.c" +#line 485 "parser.c" { if ( p == pe ) goto _test_eof; @@ -523,14 +515,14 @@ st0: cs = 0; goto _out; tr2: -#line 219 "parser.rl" +#line 211 "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 224 "parser.rl" +#line 216 "parser.rl" { char *np; if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) { @@ -550,7 +542,7 @@ tr3: } goto st29; tr7: -#line 242 "parser.rl" +#line 234 "parser.rl" { char *np; json->current_nesting++; @@ -560,7 +552,7 @@ tr7: } goto st29; tr11: -#line 250 "parser.rl" +#line 242 "parser.rl" { char *np; json->current_nesting++; @@ -570,7 +562,7 @@ tr11: } goto st29; tr25: -#line 212 "parser.rl" +#line 204 "parser.rl" { if (json->allow_nan) { *result = CInfinity; @@ -580,7 +572,7 @@ tr25: } goto st29; tr27: -#line 205 "parser.rl" +#line 197 "parser.rl" { if (json->allow_nan) { *result = CNaN; @@ -590,19 +582,19 @@ tr27: } goto st29; tr31: -#line 199 "parser.rl" +#line 191 "parser.rl" { *result = Qfalse; } goto st29; tr34: -#line 196 "parser.rl" +#line 188 "parser.rl" { *result = Qnil; } goto st29; tr37: -#line 202 "parser.rl" +#line 194 "parser.rl" { *result = Qtrue; } @@ -611,9 +603,9 @@ st29: if ( ++p == pe ) goto _test_eof29; case 29: -#line 258 "parser.rl" +#line 250 "parser.rl" { p--; {p++; cs = 29; goto _out;} } -#line 617 "parser.c" +#line 609 "parser.c" switch( (*p) ) { case 13: goto st29; case 32: goto st29; @@ -854,7 +846,7 @@ case 28: _out: {} } -#line 279 "parser.rl" +#line 271 "parser.rl" if (cs >= JSON_value_first_final) { return p; @@ -864,7 +856,7 @@ case 28: } -#line 868 "parser.c" +#line 860 "parser.c" enum {JSON_integer_start = 1}; enum {JSON_integer_first_final = 3}; enum {JSON_integer_error = 0}; @@ -872,7 +864,7 @@ enum {JSON_integer_error = 0}; enum {JSON_integer_en_main = 1}; -#line 295 "parser.rl" +#line 287 "parser.rl" static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -880,15 +872,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res int cs = EVIL; -#line 884 "parser.c" +#line 876 "parser.c" { cs = JSON_integer_start; } -#line 302 "parser.rl" +#line 294 "parser.rl" json->memo = p; -#line 892 "parser.c" +#line 884 "parser.c" { if ( p == pe ) goto _test_eof; @@ -922,14 +914,14 @@ case 3: goto st0; goto tr4; tr4: -#line 292 "parser.rl" +#line 284 "parser.rl" { p--; {p++; cs = 4; goto _out;} } goto st4; st4: if ( ++p == pe ) goto _test_eof4; case 4: -#line 933 "parser.c" +#line 925 "parser.c" goto st0; st5: if ( ++p == pe ) @@ -948,7 +940,7 @@ case 5: _out: {} } -#line 304 "parser.rl" +#line 296 "parser.rl" if (cs >= JSON_integer_first_final) { long len = p - json->memo; @@ -963,7 +955,7 @@ case 5: } -#line 967 "parser.c" +#line 959 "parser.c" enum {JSON_float_start = 1}; enum {JSON_float_first_final = 8}; enum {JSON_float_error = 0}; @@ -971,7 +963,7 @@ enum {JSON_float_error = 0}; enum {JSON_float_en_main = 1}; -#line 329 "parser.rl" +#line 321 "parser.rl" static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -979,15 +971,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul int cs = EVIL; -#line 983 "parser.c" +#line 975 "parser.c" { cs = JSON_float_start; } -#line 336 "parser.rl" +#line 328 "parser.rl" json->memo = p; -#line 991 "parser.c" +#line 983 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1045,14 +1037,14 @@ case 8: goto st0; goto tr9; tr9: -#line 323 "parser.rl" +#line 315 "parser.rl" { p--; {p++; cs = 9; goto _out;} } goto st9; st9: if ( ++p == pe ) goto _test_eof9; case 9: -#line 1056 "parser.c" +#line 1048 "parser.c" goto st0; st5: if ( ++p == pe ) @@ -1113,7 +1105,7 @@ case 7: _out: {} } -#line 338 "parser.rl" +#line 330 "parser.rl" if (cs >= JSON_float_first_final) { long len = p - json->memo; @@ -1129,7 +1121,7 @@ case 7: -#line 1133 "parser.c" +#line 1125 "parser.c" enum {JSON_array_start = 1}; enum {JSON_array_first_final = 17}; enum {JSON_array_error = 0}; @@ -1137,7 +1129,7 @@ enum {JSON_array_error = 0}; enum {JSON_array_en_main = 1}; -#line 381 "parser.rl" +#line 373 "parser.rl" static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -1151,14 +1143,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 1155 "parser.c" +#line 1147 "parser.c" { cs = JSON_array_start; } -#line 394 "parser.rl" +#line 386 "parser.rl" -#line 1162 "parser.c" +#line 1154 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1197,7 +1189,7 @@ case 2: goto st2; goto st0; tr2: -#line 358 "parser.rl" +#line 350 "parser.rl" { VALUE v = Qnil; char *np = JSON_parse_value(json, p, pe, &v); @@ -1217,7 +1209,7 @@ st3: if ( ++p == pe ) goto _test_eof3; case 3: -#line 1221 "parser.c" +#line 1213 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; @@ -1317,14 +1309,14 @@ case 12: goto st3; goto st12; tr4: -#line 373 "parser.rl" +#line 365 "parser.rl" { p--; {p++; cs = 17; goto _out;} } goto st17; st17: if ( ++p == pe ) goto _test_eof17; case 17: -#line 1328 "parser.c" +#line 1320 "parser.c" goto st0; st13: if ( ++p == pe ) @@ -1380,7 +1372,7 @@ case 16: _out: {} } -#line 395 "parser.rl" +#line 387 "parser.rl" if(cs >= JSON_array_first_final) { return p + 1; @@ -1461,7 +1453,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd) } -#line 1465 "parser.c" +#line 1457 "parser.c" enum {JSON_string_start = 1}; enum {JSON_string_first_final = 8}; enum {JSON_string_error = 0}; @@ -1469,7 +1461,7 @@ enum {JSON_string_error = 0}; enum {JSON_string_en_main = 1}; -#line 494 "parser.rl" +#line 486 "parser.rl" static int @@ -1491,15 +1483,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu *result = rb_str_buf_new(0); -#line 1495 "parser.c" +#line 1487 "parser.c" { cs = JSON_string_start; } -#line 515 "parser.rl" +#line 507 "parser.rl" json->memo = p; -#line 1503 "parser.c" +#line 1495 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1524,7 +1516,7 @@ case 2: goto st0; goto st2; tr2: -#line 480 "parser.rl" +#line 472 "parser.rl" { *result = json_string_unescape(*result, json->memo + 1, p); if (NIL_P(*result)) { @@ -1535,14 +1527,14 @@ tr2: {p = (( p + 1))-1;} } } -#line 491 "parser.rl" +#line 483 "parser.rl" { p--; {p++; cs = 8; goto _out;} } goto st8; st8: if ( ++p == pe ) goto _test_eof8; case 8: -#line 1546 "parser.c" +#line 1538 "parser.c" goto st0; st3: if ( ++p == pe ) @@ -1618,7 +1610,7 @@ case 7: _out: {} } -#line 517 "parser.rl" +#line 509 "parser.rl" if (json->create_additions && RTEST(match_string = json->match_string)) { VALUE klass; @@ -1657,7 +1649,7 @@ static VALUE convert_encoding(VALUE source) { #ifdef HAVE_RUBY_ENCODING_H { - source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8); + source = rb_str_conv_enc(source, NULL, rb_utf8_encoding()); } #endif return source; @@ -1783,7 +1775,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } -#line 1787 "parser.c" +#line 1779 "parser.c" enum {JSON_start = 1}; enum {JSON_first_final = 10}; enum {JSON_error = 0}; @@ -1791,7 +1783,7 @@ enum {JSON_error = 0}; enum {JSON_en_main = 1}; -#line 695 "parser.rl" +#line 687 "parser.rl" /* @@ -1808,16 +1800,16 @@ static VALUE cParser_parse(VALUE self) GET_PARSER; -#line 1812 "parser.c" +#line 1804 "parser.c" { cs = JSON_start; } -#line 711 "parser.rl" +#line 703 "parser.rl" p = json->source; pe = p + json->len; -#line 1821 "parser.c" +#line 1813 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1851,7 +1843,7 @@ st0: cs = 0; goto _out; tr2: -#line 687 "parser.rl" +#line 679 "parser.rl" { char *np = JSON_parse_value(json, p, pe, &result); if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} @@ -1861,7 +1853,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1865 "parser.c" +#line 1857 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -1950,7 +1942,7 @@ case 9: _out: {} } -#line 714 "parser.rl" +#line 706 "parser.rl" if (cs >= JSON_first_final && p == pe) { return result; @@ -2048,12 +2040,6 @@ void Init_parser(void) i_aset = rb_intern("[]="); i_aref = rb_intern("[]"); i_leftshift = rb_intern("<<"); -#ifdef HAVE_RUBY_ENCODING_H - CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8")); - i_encode = rb_intern("encode"); -#else - i_iconv = rb_intern("iconv"); -#endif } /* diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index b6ab64a..f35336c 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -65,14 +65,6 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch) return len; } -#ifdef HAVE_RUBY_ENCODING_H -static VALUE CEncoding_UTF_8; - -static ID i_encode; -#else -static ID i_iconv; -#endif - static VALUE mJSON, mExt, cParser, eParserError, eNestingError; static VALUE CNaN, CInfinity, CMinusInfinity; @@ -552,7 +544,7 @@ static VALUE convert_encoding(VALUE source) { #ifdef HAVE_RUBY_ENCODING_H { - source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8); + source = rb_str_conv_enc(source, NULL, rb_utf8_encoding()); } #endif return source; @@ -808,12 +800,6 @@ void Init_parser(void) i_aset = rb_intern("[]="); i_aref = rb_intern("[]"); i_leftshift = rb_intern("<<"); -#ifdef HAVE_RUBY_ENCODING_H - CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8")); - i_encode = rb_intern("encode"); -#else - i_iconv = rb_intern("iconv"); -#endif } /* -- cgit v1.2.1 From d5a77c8af98d9be4df53cecc4d876a23d7688f74 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 24 Apr 2016 02:04:34 +0900 Subject: Exception encoding Raise with messages in UTF-8 encoding. --- ext/json/ext/parser/extconf.rb | 2 + ext/json/ext/parser/parser.c | 178 +++++++++++++++++++++++------------------ ext/json/ext/parser/parser.rl | 32 ++++++-- tests/json_parser_test.rb | 10 +++ 4 files changed, 139 insertions(+), 83 deletions(-) diff --git a/ext/json/ext/parser/extconf.rb b/ext/json/ext/parser/extconf.rb index ae4f861..2addc53 100644 --- a/ext/json/ext/parser/extconf.rb +++ b/ext/json/ext/parser/extconf.rb @@ -1,3 +1,5 @@ require 'mkmf' +have_func("rb_enc_raise", "ruby.h") + create_makefile 'json/ext/parser' diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index 4bbd30c..94543d2 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -3,6 +3,28 @@ #include "../fbuffer/fbuffer.h" #include "parser.h" +#if defined HAVE_RUBY_ENCODING_H +# define EXC_ENCODING rb_utf8_encoding(), +# ifndef HAVE_RB_ENC_RAISE +static void +enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...) +{ + va_list args; + VALUE mesg; + + va_start(args, fmt); + mesg = rb_enc_vsprintf(enc, fmt, args); + va_end(args); + + rb_exc_raise(rb_exc_new3(exc, mesg)); +} +# define rb_enc_raise enc_raise +# endif +#else +# define EXC_ENCODING /* nothing */ +# define rb_enc_raise rb_raise +#endif + /* unicode */ static const char digit_values[256] = { @@ -76,11 +98,11 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, i_match_string, i_aset, i_aref, i_leftshift; -#line 102 "parser.rl" +#line 124 "parser.rl" -#line 84 "parser.c" +#line 106 "parser.c" enum {JSON_object_start = 1}; enum {JSON_object_first_final = 27}; enum {JSON_object_error = 0}; @@ -88,7 +110,7 @@ enum {JSON_object_error = 0}; enum {JSON_object_en_main = 1}; -#line 143 "parser.rl" +#line 165 "parser.rl" static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -104,14 +126,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class); -#line 108 "parser.c" +#line 130 "parser.c" { cs = JSON_object_start; } -#line 158 "parser.rl" +#line 180 "parser.rl" -#line 115 "parser.c" +#line 137 "parser.c" { if ( p == pe ) goto _test_eof; @@ -139,7 +161,7 @@ case 2: goto st2; goto st0; tr2: -#line 125 "parser.rl" +#line 147 "parser.rl" { char *np; json->parsing_name = 1; @@ -152,7 +174,7 @@ st3: if ( ++p == pe ) goto _test_eof3; case 3: -#line 156 "parser.c" +#line 178 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; @@ -219,7 +241,7 @@ case 8: goto st8; goto st0; tr11: -#line 110 "parser.rl" +#line 132 "parser.rl" { VALUE v = Qnil; char *np = JSON_parse_value(json, p, pe, &v); @@ -239,7 +261,7 @@ st9: if ( ++p == pe ) goto _test_eof9; case 9: -#line 243 "parser.c" +#line 265 "parser.c" switch( (*p) ) { case 13: goto st9; case 32: goto st9; @@ -328,14 +350,14 @@ case 18: goto st9; goto st18; tr4: -#line 133 "parser.rl" +#line 155 "parser.rl" { p--; {p++; cs = 27; goto _out;} } goto st27; st27: if ( ++p == pe ) goto _test_eof27; case 27: -#line 339 "parser.c" +#line 361 "parser.c" goto st0; st19: if ( ++p == pe ) @@ -433,7 +455,7 @@ case 26: _out: {} } -#line 159 "parser.rl" +#line 181 "parser.rl" if (cs >= JSON_object_first_final) { if (json->create_additions) { @@ -458,7 +480,7 @@ case 26: -#line 462 "parser.c" +#line 484 "parser.c" enum {JSON_value_start = 1}; enum {JSON_value_first_final = 29}; enum {JSON_value_error = 0}; @@ -466,7 +488,7 @@ enum {JSON_value_error = 0}; enum {JSON_value_en_main = 1}; -#line 263 "parser.rl" +#line 285 "parser.rl" static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -474,14 +496,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul int cs = EVIL; -#line 478 "parser.c" +#line 500 "parser.c" { cs = JSON_value_start; } -#line 270 "parser.rl" +#line 292 "parser.rl" -#line 485 "parser.c" +#line 507 "parser.c" { if ( p == pe ) goto _test_eof; @@ -515,14 +537,14 @@ st0: cs = 0; goto _out; tr2: -#line 211 "parser.rl" +#line 233 "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 216 "parser.rl" +#line 238 "parser.rl" { char *np; if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) { @@ -531,7 +553,7 @@ tr3: {p = (( p + 10))-1;} p--; {p++; cs = 29; goto _out;} } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); + rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p); } } np = JSON_parse_float(json, p, pe, result); @@ -542,7 +564,7 @@ tr3: } goto st29; tr7: -#line 234 "parser.rl" +#line 256 "parser.rl" { char *np; json->current_nesting++; @@ -552,7 +574,7 @@ tr7: } goto st29; tr11: -#line 242 "parser.rl" +#line 264 "parser.rl" { char *np; json->current_nesting++; @@ -562,39 +584,39 @@ tr11: } goto st29; tr25: -#line 204 "parser.rl" +#line 226 "parser.rl" { if (json->allow_nan) { *result = CInfinity; } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8); + rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8); } } goto st29; tr27: -#line 197 "parser.rl" +#line 219 "parser.rl" { if (json->allow_nan) { *result = CNaN; } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2); + rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2); } } goto st29; tr31: -#line 191 "parser.rl" +#line 213 "parser.rl" { *result = Qfalse; } goto st29; tr34: -#line 188 "parser.rl" +#line 210 "parser.rl" { *result = Qnil; } goto st29; tr37: -#line 194 "parser.rl" +#line 216 "parser.rl" { *result = Qtrue; } @@ -603,9 +625,9 @@ st29: if ( ++p == pe ) goto _test_eof29; case 29: -#line 250 "parser.rl" +#line 272 "parser.rl" { p--; {p++; cs = 29; goto _out;} } -#line 609 "parser.c" +#line 631 "parser.c" switch( (*p) ) { case 13: goto st29; case 32: goto st29; @@ -846,7 +868,7 @@ case 28: _out: {} } -#line 271 "parser.rl" +#line 293 "parser.rl" if (cs >= JSON_value_first_final) { return p; @@ -856,7 +878,7 @@ case 28: } -#line 860 "parser.c" +#line 882 "parser.c" enum {JSON_integer_start = 1}; enum {JSON_integer_first_final = 3}; enum {JSON_integer_error = 0}; @@ -864,7 +886,7 @@ enum {JSON_integer_error = 0}; enum {JSON_integer_en_main = 1}; -#line 287 "parser.rl" +#line 309 "parser.rl" static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -872,15 +894,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res int cs = EVIL; -#line 876 "parser.c" +#line 898 "parser.c" { cs = JSON_integer_start; } -#line 294 "parser.rl" +#line 316 "parser.rl" json->memo = p; -#line 884 "parser.c" +#line 906 "parser.c" { if ( p == pe ) goto _test_eof; @@ -914,14 +936,14 @@ case 3: goto st0; goto tr4; tr4: -#line 284 "parser.rl" +#line 306 "parser.rl" { p--; {p++; cs = 4; goto _out;} } goto st4; st4: if ( ++p == pe ) goto _test_eof4; case 4: -#line 925 "parser.c" +#line 947 "parser.c" goto st0; st5: if ( ++p == pe ) @@ -940,7 +962,7 @@ case 5: _out: {} } -#line 296 "parser.rl" +#line 318 "parser.rl" if (cs >= JSON_integer_first_final) { long len = p - json->memo; @@ -955,7 +977,7 @@ case 5: } -#line 959 "parser.c" +#line 981 "parser.c" enum {JSON_float_start = 1}; enum {JSON_float_first_final = 8}; enum {JSON_float_error = 0}; @@ -963,7 +985,7 @@ enum {JSON_float_error = 0}; enum {JSON_float_en_main = 1}; -#line 321 "parser.rl" +#line 343 "parser.rl" static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -971,15 +993,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul int cs = EVIL; -#line 975 "parser.c" +#line 997 "parser.c" { cs = JSON_float_start; } -#line 328 "parser.rl" +#line 350 "parser.rl" json->memo = p; -#line 983 "parser.c" +#line 1005 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1037,14 +1059,14 @@ case 8: goto st0; goto tr9; tr9: -#line 315 "parser.rl" +#line 337 "parser.rl" { p--; {p++; cs = 9; goto _out;} } goto st9; st9: if ( ++p == pe ) goto _test_eof9; case 9: -#line 1048 "parser.c" +#line 1070 "parser.c" goto st0; st5: if ( ++p == pe ) @@ -1105,7 +1127,7 @@ case 7: _out: {} } -#line 330 "parser.rl" +#line 352 "parser.rl" if (cs >= JSON_float_first_final) { long len = p - json->memo; @@ -1121,7 +1143,7 @@ case 7: -#line 1125 "parser.c" +#line 1147 "parser.c" enum {JSON_array_start = 1}; enum {JSON_array_first_final = 17}; enum {JSON_array_error = 0}; @@ -1129,7 +1151,7 @@ enum {JSON_array_error = 0}; enum {JSON_array_en_main = 1}; -#line 373 "parser.rl" +#line 395 "parser.rl" static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -1143,14 +1165,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 1147 "parser.c" +#line 1169 "parser.c" { cs = JSON_array_start; } -#line 386 "parser.rl" +#line 408 "parser.rl" -#line 1154 "parser.c" +#line 1176 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1189,7 +1211,7 @@ case 2: goto st2; goto st0; tr2: -#line 350 "parser.rl" +#line 372 "parser.rl" { VALUE v = Qnil; char *np = JSON_parse_value(json, p, pe, &v); @@ -1209,7 +1231,7 @@ st3: if ( ++p == pe ) goto _test_eof3; case 3: -#line 1213 "parser.c" +#line 1235 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; @@ -1309,14 +1331,14 @@ case 12: goto st3; goto st12; tr4: -#line 365 "parser.rl" +#line 387 "parser.rl" { p--; {p++; cs = 17; goto _out;} } goto st17; st17: if ( ++p == pe ) goto _test_eof17; case 17: -#line 1320 "parser.c" +#line 1342 "parser.c" goto st0; st13: if ( ++p == pe ) @@ -1372,12 +1394,12 @@ case 16: _out: {} } -#line 387 "parser.rl" +#line 409 "parser.rl" if(cs >= JSON_array_first_final) { return p + 1; } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); + rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p); return NULL; } } @@ -1453,7 +1475,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd) } -#line 1457 "parser.c" +#line 1479 "parser.c" enum {JSON_string_start = 1}; enum {JSON_string_first_final = 8}; enum {JSON_string_error = 0}; @@ -1461,7 +1483,7 @@ enum {JSON_string_error = 0}; enum {JSON_string_en_main = 1}; -#line 486 "parser.rl" +#line 508 "parser.rl" static int @@ -1483,15 +1505,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu *result = rb_str_buf_new(0); -#line 1487 "parser.c" +#line 1509 "parser.c" { cs = JSON_string_start; } -#line 507 "parser.rl" +#line 529 "parser.rl" json->memo = p; -#line 1495 "parser.c" +#line 1517 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1516,7 +1538,7 @@ case 2: goto st0; goto st2; tr2: -#line 472 "parser.rl" +#line 494 "parser.rl" { *result = json_string_unescape(*result, json->memo + 1, p); if (NIL_P(*result)) { @@ -1527,14 +1549,14 @@ tr2: {p = (( p + 1))-1;} } } -#line 483 "parser.rl" +#line 505 "parser.rl" { p--; {p++; cs = 8; goto _out;} } goto st8; st8: if ( ++p == pe ) goto _test_eof8; case 8: -#line 1538 "parser.c" +#line 1560 "parser.c" goto st0; st3: if ( ++p == pe ) @@ -1610,7 +1632,7 @@ case 7: _out: {} } -#line 509 "parser.rl" +#line 531 "parser.rl" if (json->create_additions && RTEST(match_string = json->match_string)) { VALUE klass; @@ -1775,7 +1797,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } -#line 1779 "parser.c" +#line 1801 "parser.c" enum {JSON_start = 1}; enum {JSON_first_final = 10}; enum {JSON_error = 0}; @@ -1783,7 +1805,7 @@ enum {JSON_error = 0}; enum {JSON_en_main = 1}; -#line 687 "parser.rl" +#line 709 "parser.rl" /* @@ -1800,16 +1822,16 @@ static VALUE cParser_parse(VALUE self) GET_PARSER; -#line 1804 "parser.c" +#line 1826 "parser.c" { cs = JSON_start; } -#line 703 "parser.rl" +#line 725 "parser.rl" p = json->source; pe = p + json->len; -#line 1813 "parser.c" +#line 1835 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1843,7 +1865,7 @@ st0: cs = 0; goto _out; tr2: -#line 679 "parser.rl" +#line 701 "parser.rl" { char *np = JSON_parse_value(json, p, pe, &result); if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} @@ -1853,7 +1875,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1857 "parser.c" +#line 1879 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -1942,12 +1964,12 @@ case 9: _out: {} } -#line 706 "parser.rl" +#line 728 "parser.rl" if (cs >= JSON_first_final && p == pe) { return result; } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); + rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p); return Qnil; } } diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index f35336c..fa2880f 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -1,6 +1,28 @@ #include "../fbuffer/fbuffer.h" #include "parser.h" +#if defined HAVE_RUBY_ENCODING_H +# define EXC_ENCODING rb_utf8_encoding(), +# ifndef HAVE_RB_ENC_RAISE +static void +enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...) +{ + va_list args; + VALUE mesg; + + va_start(args, fmt); + mesg = rb_enc_vsprintf(enc, fmt, args); + va_end(args); + + rb_exc_raise(rb_exc_new3(exc, mesg)); +} +# define rb_enc_raise enc_raise +# endif +#else +# define EXC_ENCODING /* nothing */ +# define rb_enc_raise rb_raise +#endif + /* unicode */ static const char digit_values[256] = { @@ -198,14 +220,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu if (json->allow_nan) { *result = CNaN; } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2); + rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2); } } action parse_infinity { if (json->allow_nan) { *result = CInfinity; } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8); + rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8); } } action parse_string { @@ -221,7 +243,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu fexec p + 10; fhold; fbreak; } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); + rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p); } } np = JSON_parse_float(json, fpc, pe, result); @@ -388,7 +410,7 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul if(cs >= JSON_array_first_final) { return p + 1; } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); + rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p); return NULL; } } @@ -707,7 +729,7 @@ static VALUE cParser_parse(VALUE self) if (cs >= JSON_first_final && p == pe) { return result; } else { - rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p); + rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p); return Qnil; } } diff --git a/tests/json_parser_test.rb b/tests/json_parser_test.rb index 46fa47c..ee28578 100644 --- a/tests/json_parser_test.rb +++ b/tests/json_parser_test.rb @@ -17,6 +17,16 @@ class JSONParserTest < Test::Unit::TestCase assert_equal Encoding::UTF_16, source.encoding end if defined?(Encoding::UTF_16) + def test_error_message_encoding + bug10705 = '[ruby-core:67386] [Bug #10705]' + json = ".\"\xE2\x88\x9A\"".force_encoding(Encoding::UTF_8) + e = assert_raise(JSON::ParserError) { + JSON::Ext::Parser.new(json).parse + } + assert_equal(Encoding::UTF_8, e.message.encoding, bug10705) + assert_include(e.message, json, bug10705) + end if defined?(Encoding::UTF_8) and defined?(JSON::Ext::Parser) + def test_parsing parser = JSON::Parser.new('"test"') assert_equal 'test', parser.parse -- cgit v1.2.1 From e7fe550e6e0b9d963908406ccc46a374789c92b6 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 24 Apr 2016 02:08:30 +0900 Subject: Optional hash in rb_scan_args Use ':' in rb_scan_args to get optional hash, which available since ruby 2.1. --- ext/json/ext/parser/parser.c | 24 ++++++++++++++++-------- ext/json/ext/parser/parser.rl | 8 ++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index 94543d2..9360247 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -1712,12 +1712,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) if (json->Vsource) { rb_raise(rb_eTypeError, "already initialized instance"); } +#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH + rb_scan_args(argc, argv, "1:", &source, &opts); +#else rb_scan_args(argc, argv, "11", &source, &opts); +#endif if (!NIL_P(opts)) { +#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash"); if (NIL_P(opts)) { rb_raise(rb_eArgError, "opts needs to be like a hash"); } else { +#endif VALUE tmp = ID2SYM(i_max_nesting); if (option_given_p(opts, tmp)) { VALUE max_nesting = rb_hash_aref(opts, tmp); @@ -1778,7 +1784,9 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } else { json->match_string = Qnil; } +#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH } +#endif } else { json->max_nesting = 100; json->allow_nan = 0; @@ -1797,7 +1805,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } -#line 1801 "parser.c" +#line 1809 "parser.c" enum {JSON_start = 1}; enum {JSON_first_final = 10}; enum {JSON_error = 0}; @@ -1805,7 +1813,7 @@ enum {JSON_error = 0}; enum {JSON_en_main = 1}; -#line 709 "parser.rl" +#line 717 "parser.rl" /* @@ -1822,16 +1830,16 @@ static VALUE cParser_parse(VALUE self) GET_PARSER; -#line 1826 "parser.c" +#line 1834 "parser.c" { cs = JSON_start; } -#line 725 "parser.rl" +#line 733 "parser.rl" p = json->source; pe = p + json->len; -#line 1835 "parser.c" +#line 1843 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1865,7 +1873,7 @@ st0: cs = 0; goto _out; tr2: -#line 701 "parser.rl" +#line 709 "parser.rl" { char *np = JSON_parse_value(json, p, pe, &result); if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;} @@ -1875,7 +1883,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1879 "parser.c" +#line 1887 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -1964,7 +1972,7 @@ case 9: _out: {} } -#line 728 "parser.rl" +#line 736 "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 fa2880f..cc7e164 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -607,12 +607,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) if (json->Vsource) { rb_raise(rb_eTypeError, "already initialized instance"); } +#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH + rb_scan_args(argc, argv, "1:", &source, &opts); +#else rb_scan_args(argc, argv, "11", &source, &opts); +#endif if (!NIL_P(opts)) { +#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash"); if (NIL_P(opts)) { rb_raise(rb_eArgError, "opts needs to be like a hash"); } else { +#endif VALUE tmp = ID2SYM(i_max_nesting); if (option_given_p(opts, tmp)) { VALUE max_nesting = rb_hash_aref(opts, tmp); @@ -673,7 +679,9 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) } else { json->match_string = Qnil; } +#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH } +#endif } else { json->max_nesting = 100; json->allow_nan = 0; -- cgit v1.2.1 From 39b6654d6f68b8431ac79e12e852b6448bc4fe79 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 24 Apr 2016 02:31:53 +0900 Subject: Add frozen_string_literal: false When you change this to true, you may need to add more tests. --- lib/json.rb | 1 + lib/json/add/bigdecimal.rb | 1 + lib/json/add/complex.rb | 1 + lib/json/add/core.rb | 1 + lib/json/add/date.rb | 1 + lib/json/add/date_time.rb | 1 + lib/json/add/exception.rb | 1 + lib/json/add/ostruct.rb | 1 + lib/json/add/range.rb | 1 + lib/json/add/rational.rb | 1 + lib/json/add/regexp.rb | 1 + lib/json/add/struct.rb | 1 + lib/json/add/symbol.rb | 1 + lib/json/add/time.rb | 1 + lib/json/common.rb | 1 + lib/json/ext.rb | 1 + lib/json/generic_object.rb | 1 + lib/json/pure.rb | 1 + lib/json/pure/generator.rb | 1 + lib/json/pure/parser.rb | 1 + lib/json/version.rb | 1 + tests/json_addition_test.rb | 1 + tests/json_common_interface_test.rb | 1 + tests/json_encoding_test.rb | 1 + tests/json_ext_parser_test.rb | 1 + tests/json_fixtures_test.rb | 1 + tests/json_generic_object_test.rb | 1 + tests/json_parser_test.rb | 1 + tests/json_string_matching_test.rb | 1 + 29 files changed, 29 insertions(+) diff --git a/lib/json.rb b/lib/json.rb index 24aa385..b5a6912 100644 --- a/lib/json.rb +++ b/lib/json.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'json/common' ## diff --git a/lib/json/add/bigdecimal.rb b/lib/json/add/bigdecimal.rb index 0ef69f1..539daee 100644 --- a/lib/json/add/bigdecimal.rb +++ b/lib/json/add/bigdecimal.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/add/complex.rb b/lib/json/add/complex.rb index 3d653bb..28ef734 100644 --- a/lib/json/add/complex.rb +++ b/lib/json/add/complex.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/add/core.rb b/lib/json/add/core.rb index 77d9dc0..bfb017c 100644 --- a/lib/json/add/core.rb +++ b/lib/json/add/core.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false # This file requires the implementations of ruby core's custom objects for # serialisation/deserialisation. diff --git a/lib/json/add/date.rb b/lib/json/add/date.rb index 4288237..6a9f16e 100644 --- a/lib/json/add/date.rb +++ b/lib/json/add/date.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/add/date_time.rb b/lib/json/add/date_time.rb index 5ea42ea..0edeeda 100644 --- a/lib/json/add/date_time.rb +++ b/lib/json/add/date_time.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/add/exception.rb b/lib/json/add/exception.rb index e6ad257..d6ecfed 100644 --- a/lib/json/add/exception.rb +++ b/lib/json/add/exception.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/add/ostruct.rb b/lib/json/add/ostruct.rb index da81e10..b8bf8ed 100644 --- a/lib/json/add/ostruct.rb +++ b/lib/json/add/ostruct.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/add/range.rb b/lib/json/add/range.rb index e61e553..d9c97dd 100644 --- a/lib/json/add/range.rb +++ b/lib/json/add/range.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/add/rational.rb b/lib/json/add/rational.rb index ee39c20..356940b 100644 --- a/lib/json/add/rational.rb +++ b/lib/json/add/rational.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/add/regexp.rb b/lib/json/add/regexp.rb index 2fcbb6f..df945ba 100644 --- a/lib/json/add/regexp.rb +++ b/lib/json/add/regexp.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/add/struct.rb b/lib/json/add/struct.rb index 6847cde..2180207 100644 --- a/lib/json/add/struct.rb +++ b/lib/json/add/struct.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/add/symbol.rb b/lib/json/add/symbol.rb index 03dc9a5..1f07bf7 100644 --- a/lib/json/add/symbol.rb +++ b/lib/json/add/symbol.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/add/time.rb b/lib/json/add/time.rb index d983467..d0cb97d 100644 --- a/lib/json/add/time.rb +++ b/lib/json/add/time.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end diff --git a/lib/json/common.rb b/lib/json/common.rb index 1215d41..57001b5 100644 --- a/lib/json/common.rb +++ b/lib/json/common.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'json/version' require 'json/generic_object' diff --git a/lib/json/ext.rb b/lib/json/ext.rb index c5f8131..44c2b65 100644 --- a/lib/json/ext.rb +++ b/lib/json/ext.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false if ENV['SIMPLECOV_COVERAGE'].to_i == 1 require 'simplecov' SimpleCov.start do diff --git a/lib/json/generic_object.rb b/lib/json/generic_object.rb index 3a14f0e..6c8f039 100644 --- a/lib/json/generic_object.rb +++ b/lib/json/generic_object.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'ostruct' module JSON diff --git a/lib/json/pure.rb b/lib/json/pure.rb index b68668b..6bee334 100644 --- a/lib/json/pure.rb +++ b/lib/json/pure.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false if ENV['SIMPLECOV_COVERAGE'].to_i == 1 require 'simplecov' SimpleCov.start do diff --git a/lib/json/pure/generator.rb b/lib/json/pure/generator.rb index cc8b0fd..fdb0e2a 100644 --- a/lib/json/pure/generator.rb +++ b/lib/json/pure/generator.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false module JSON MAP = { "\x0" => '\u0000', diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb index c5d1501..f80e3b2 100644 --- a/lib/json/pure/parser.rb +++ b/lib/json/pure/parser.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'strscan' module JSON diff --git a/lib/json/version.rb b/lib/json/version.rb index b91ccd7..b4d1b3b 100644 --- a/lib/json/version.rb +++ b/lib/json/version.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false module JSON # JSON version VERSION = '2.0.0' diff --git a/tests/json_addition_test.rb b/tests/json_addition_test.rb index cb07659..a028e0f 100644 --- a/tests/json_addition_test.rb +++ b/tests/json_addition_test.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'test_helper' require 'json/add/core' require 'json/add/complex' diff --git a/tests/json_common_interface_test.rb b/tests/json_common_interface_test.rb index 6e02310..b09f857 100644 --- a/tests/json_common_interface_test.rb +++ b/tests/json_common_interface_test.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'test_helper' require 'stringio' require 'tempfile' diff --git a/tests/json_encoding_test.rb b/tests/json_encoding_test.rb index 588e9a2..080c3ec 100644 --- a/tests/json_encoding_test.rb +++ b/tests/json_encoding_test.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'test_helper' class JSONEncodingTest < Test::Unit::TestCase diff --git a/tests/json_ext_parser_test.rb b/tests/json_ext_parser_test.rb index da3bdc1..761ae5e 100644 --- a/tests/json_ext_parser_test.rb +++ b/tests/json_ext_parser_test.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'test_helper' require 'stringio' require 'tempfile' diff --git a/tests/json_fixtures_test.rb b/tests/json_fixtures_test.rb index 0419983..01954fe 100644 --- a/tests/json_fixtures_test.rb +++ b/tests/json_fixtures_test.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'test_helper' class JSONFixturesTest < Test::Unit::TestCase diff --git a/tests/json_generic_object_test.rb b/tests/json_generic_object_test.rb index 171fdb8..82742dc 100644 --- a/tests/json_generic_object_test.rb +++ b/tests/json_generic_object_test.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'test_helper' class JSONGenericObjectTest < Test::Unit::TestCase diff --git a/tests/json_parser_test.rb b/tests/json_parser_test.rb index ee28578..3ccf6b8 100644 --- a/tests/json_parser_test.rb +++ b/tests/json_parser_test.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'test_helper' require 'stringio' require 'tempfile' diff --git a/tests/json_string_matching_test.rb b/tests/json_string_matching_test.rb index 7fec841..5d55dc3 100644 --- a/tests/json_string_matching_test.rb +++ b/tests/json_string_matching_test.rb @@ -1,3 +1,4 @@ +#frozen_string_literal: false require 'test_helper' require 'time' -- cgit v1.2.1