From 7d2ad6d6556da03300a5aeadeeacaec563435773 Mon Sep 17 00:00:00 2001 From: Florian Frank Date: Thu, 2 Jun 2016 21:10:36 +0200 Subject: Remove quirks mode --- Gemfile | 2 - TODO | 1 - ext/json/ext/generator/generator.c | 34 +-- ext/json/ext/generator/generator.h | 1 - java/src/json/ext/Generator.java | 7 +- java/src/json/ext/GeneratorState.java | 6 +- java/src/json/ext/OptionsReader.java | 2 +- java/src/json/ext/Parser.java | 512 +++++++--------------------------- java/src/json/ext/Parser.rl | 135 ++------- java/src/json/ext/RuntimeInfo.java | 4 - json.gemspec | Bin 4444 -> 4470 bytes json_pure.gemspec | 4 +- lib/json/common.rb | 9 +- lib/json/pure/generator.rb | 13 - lib/json/pure/parser.rb | 16 +- tests/json_common_interface_test.rb | 7 +- tests/json_generator_test.rb | 3 - tests/json_parser_test.rb | 2 +- tests/test_helper.rb | 4 - 19 files changed, 143 insertions(+), 619 deletions(-) delete mode 100644 TODO diff --git a/Gemfile b/Gemfile index 51ff10a..71fac47 100644 --- a/Gemfile +++ b/Gemfile @@ -5,5 +5,3 @@ source 'https://rubygems.org' gemspec :name => 'json' gemspec :name => 'json_pure' gemspec :name => 'json-java' - -gem 'simplecov' diff --git a/TODO b/TODO deleted file mode 100644 index 8b13789..0000000 --- a/TODO +++ /dev/null @@ -1 +0,0 @@ - diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c index 393e29c..2a3db29 100644 --- a/ext/json/ext/generator/generator.c +++ b/ext/json/ext/generator/generator.c @@ -14,7 +14,7 @@ static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject, static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before, i_object_nl, i_array_nl, i_max_nesting, i_allow_nan, i_ascii_only, - i_quirks_mode, i_pack, i_unpack, i_create_id, i_extend, i_key_p, + i_pack, i_unpack, i_create_id, i_extend, i_key_p, i_aref, i_send, i_respond_to_p, i_match, i_keys, i_depth, i_buffer_initial_length, i_dup; @@ -622,8 +622,6 @@ static VALUE cState_configure(VALUE self, VALUE opts) state->allow_nan = RTEST(tmp); tmp = rb_hash_aref(opts, ID2SYM(i_ascii_only)); state->ascii_only = RTEST(tmp); - tmp = rb_hash_aref(opts, ID2SYM(i_quirks_mode)); - state->quirks_mode = RTEST(tmp); return self; } @@ -657,7 +655,6 @@ static VALUE cState_to_h(VALUE self) rb_hash_aset(result, ID2SYM(i_array_nl), rb_str_new(state->array_nl, state->array_nl_len)); rb_hash_aset(result, ID2SYM(i_allow_nan), state->allow_nan ? Qtrue : Qfalse); rb_hash_aset(result, ID2SYM(i_ascii_only), state->ascii_only ? Qtrue : Qfalse); - rb_hash_aset(result, ID2SYM(i_quirks_mode), state->quirks_mode ? Qtrue : Qfalse); rb_hash_aset(result, ID2SYM(i_max_nesting), LONG2FIX(state->max_nesting)); rb_hash_aset(result, ID2SYM(i_depth), LONG2FIX(state->depth)); rb_hash_aset(result, ID2SYM(i_buffer_initial_length), LONG2FIX(state->buffer_initial_length)); @@ -943,8 +940,6 @@ static VALUE cState_generate(VALUE self, VALUE obj) * * *allow_nan*: true if NaN, Infinity, and -Infinity should be * generated, otherwise an exception is thrown, if these values are * encountered. This options defaults to false. - * * *quirks_mode*: Enables quirks_mode for parser, that is for example - * generating single JSON values instead of documents is possible. * * *buffer_initial_length*: sets the initial length of the generator's * internal buffer. */ @@ -1251,29 +1246,6 @@ static VALUE cState_ascii_only_p(VALUE self) return state->ascii_only ? Qtrue : Qfalse; } -/* - * call-seq: quirks_mode? - * - * Returns true, if quirks mode is enabled. Otherwise returns false. - */ -static VALUE cState_quirks_mode_p(VALUE self) -{ - GET_STATE(self); - return state->quirks_mode ? Qtrue : Qfalse; -} - -/* - * call-seq: quirks_mode=(enable) - * - * If set to true, enables the quirks_mode mode. - */ -static VALUE cState_quirks_mode_set(VALUE self, VALUE enable) -{ - GET_STATE(self); - state->quirks_mode = RTEST(enable); - return Qnil; -} - /* * call-seq: depth * @@ -1362,9 +1334,6 @@ void Init_generator(void) rb_define_method(cState, "check_circular?", cState_check_circular_p, 0); rb_define_method(cState, "allow_nan?", cState_allow_nan_p, 0); rb_define_method(cState, "ascii_only?", cState_ascii_only_p, 0); - rb_define_method(cState, "quirks_mode?", cState_quirks_mode_p, 0); - rb_define_method(cState, "quirks_mode", cState_quirks_mode_p, 0); - rb_define_method(cState, "quirks_mode=", cState_quirks_mode_set, 1); rb_define_method(cState, "depth", cState_depth, 0); rb_define_method(cState, "depth=", cState_depth_set, 1); rb_define_method(cState, "buffer_initial_length", cState_buffer_initial_length, 0); @@ -1416,7 +1385,6 @@ void Init_generator(void) i_max_nesting = rb_intern("max_nesting"); i_allow_nan = rb_intern("allow_nan"); i_ascii_only = rb_intern("ascii_only"); - i_quirks_mode = rb_intern("quirks_mode"); i_depth = rb_intern("depth"); i_buffer_initial_length = rb_intern("buffer_initial_length"); i_pack = rb_intern("pack"); diff --git a/ext/json/ext/generator/generator.h b/ext/json/ext/generator/generator.h index 298c0a4..7432f26 100644 --- a/ext/json/ext/generator/generator.h +++ b/ext/json/ext/generator/generator.h @@ -73,7 +73,6 @@ typedef struct JSON_Generator_StateStruct { long max_nesting; char allow_nan; char ascii_only; - char quirks_mode; long depth; long buffer_initial_length; } JSON_Generator_State; diff --git a/java/src/json/ext/Generator.java b/java/src/json/ext/Generator.java index bb3a394..96a5e7e 100644 --- a/java/src/json/ext/Generator.java +++ b/java/src/json/ext/Generator.java @@ -172,9 +172,7 @@ public final class Generator { result = RubyString.newString(session.getRuntime(), buffer); ThreadContext context = session.getContext(); RuntimeInfo info = session.getInfo(); - if (info.encodingsSupported()) { - result.force_encoding(context, info.utf8.get()); - } + result.force_encoding(context, info.utf8.get()); return result; } @@ -381,8 +379,7 @@ public final class Generator { RuntimeInfo info = session.getInfo(); RubyString src; - if (info.encodingsSupported() && - object.encoding(session.getContext()) != info.utf8.get()) { + if (object.encoding(session.getContext()) != info.utf8.get()) { src = (RubyString)object.encode(session.getContext(), info.utf8.get()); } else { diff --git a/java/src/json/ext/GeneratorState.java b/java/src/json/ext/GeneratorState.java index 11d98d0..f43087b 100644 --- a/java/src/json/ext/GeneratorState.java +++ b/java/src/json/ext/GeneratorState.java @@ -208,9 +208,7 @@ public class GeneratorState extends RubyObject { public IRubyObject generate(ThreadContext context, IRubyObject obj) { RubyString result = Generator.generateJson(context, obj, this); RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime()); - if (info.encodingsSupported()) { - result.force_encoding(context, info.utf8.get()); - } + result.force_encoding(context, info.utf8.get()); return result; } @@ -412,7 +410,7 @@ public class GeneratorState extends RubyObject { private ByteList prepareByteList(ThreadContext context, IRubyObject value) { RubyString str = value.convertToString(); RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime()); - if (info.encodingsSupported() && str.encoding(context) != info.utf8.get()) { + if (str.encoding(context) != info.utf8.get()) { str = (RubyString)str.encode(context, info.utf8.get()); } return str.getByteList().dup(); diff --git a/java/src/json/ext/OptionsReader.java b/java/src/json/ext/OptionsReader.java index 9bb6e64..70426d4 100644 --- a/java/src/json/ext/OptionsReader.java +++ b/java/src/json/ext/OptionsReader.java @@ -84,7 +84,7 @@ final class OptionsReader { RubyString str = value.convertToString(); RuntimeInfo info = getRuntimeInfo(); - if (info.encodingsSupported() && str.encoding(context) != info.utf8.get()) { + if (str.encoding(context) != info.utf8.get()) { str = (RubyString)str.encode(context, info.utf8.get()); } return str; diff --git a/java/src/json/ext/Parser.java b/java/src/json/ext/Parser.java index 5458fb1..57053e9 100644 --- a/java/src/json/ext/Parser.java +++ b/java/src/json/ext/Parser.java @@ -52,10 +52,9 @@ public class Parser extends RubyObject { private int maxNesting; private boolean allowNaN; private boolean symbolizeNames; - private boolean quirksMode; private RubyClass objectClass; private RubyClass arrayClass; - private RubyHash match_string; + private RubyHash matchString; private static final int DEFAULT_MAX_NESTING = 100; @@ -123,10 +122,6 @@ public class Parser extends RubyObject { *
If set to true, returns symbols for the names (keys) in * a JSON object. Otherwise strings are returned, which is also the default. * - *
:quirks_mode? - *
If set to true, if the parse is in quirks_mode, false - * otherwise. - * *
:create_additions *
If set to false, the Parser doesn't create additions * even if a matching class and create_id was found. This option @@ -138,9 +133,6 @@ public class Parser extends RubyObject { *
:array_class *
Defaults to Array. * - *
:quirks_mode - *
Enables quirks_mode for parser, that is for example parsing single - * JSON values instead of documents is possible. * */ @JRubyMethod(name = "new", required = 1, optional = 1, meta = true) @@ -163,15 +155,20 @@ public class Parser extends RubyObject { this.maxNesting = opts.getInt("max_nesting", DEFAULT_MAX_NESTING); this.allowNaN = opts.getBool("allow_nan", false); this.symbolizeNames = opts.getBool("symbolize_names", false); - this.quirksMode = opts.getBool("quirks_mode", false); this.createId = opts.getString("create_id", getCreateId(context)); this.createAdditions = opts.getBool("create_additions", false); this.objectClass = opts.getClass("object_class", runtime.getHash()); this.arrayClass = opts.getClass("array_class", runtime.getArray()); - this.match_string = opts.getHash("match_string"); + this.matchString = opts.getHash("match_string"); + if(symbolizeNames && createAdditions) { + throw runtime.newArgumentError( + "options :symbolize_names and :create_additions cannot be " + + " used in conjunction" + ); + } this.vSource = args[0].convertToString(); - if (!quirksMode) this.vSource = convertEncoding(context, vSource); + this.vSource = convertEncoding(context, vSource); return this; } @@ -182,33 +179,7 @@ public class Parser extends RubyObject { * Returns the source string if no conversion is needed. */ private RubyString convertEncoding(ThreadContext context, RubyString source) { - ByteList bl = source.getByteList(); - int len = bl.length(); - if (len < 2) { - throw Utils.newException(context, Utils.M_PARSER_ERROR, - "A JSON text must at least contain two octets!"); - } - - if (info.encodingsSupported()) { - RubyEncoding encoding = (RubyEncoding)source.encoding(context); - if (encoding != info.ascii8bit.get()) { - return (RubyString)source.encode(context, info.utf8.get()); - } - - String sniffedEncoding = sniffByteList(bl); - if (sniffedEncoding == null) return source; // assume UTF-8 - return reinterpretEncoding(context, source, sniffedEncoding); - } - - String sniffedEncoding = sniffByteList(bl); - if (sniffedEncoding == null) return source; // assume UTF-8 - Ruby runtime = context.getRuntime(); - return (RubyString)info.jsonModule.get(). - callMethod(context, "iconv", - new IRubyObject[] { - runtime.newString("utf-8"), - runtime.newString(sniffedEncoding), - source}); + return (RubyString)source.encode(context, info.utf8.get()); } /** @@ -261,17 +232,6 @@ public class Parser extends RubyObject { return checkAndGetSource().dup(); } - /** - * Parser#quirks_mode?() - * - *

If set to true, if the parse is in quirks_mode, false - * otherwise. - */ - @JRubyMethod(name = "quirks_mode?") - public IRubyObject quirks_mode_p(ThreadContext context) { - return context.getRuntime().newBoolean(quirksMode); - } - public RubyString checkAndGetSource() { if (vSource != null) { return vSource; @@ -338,11 +298,11 @@ public class Parser extends RubyObject { } -// line 365 "Parser.rl" +// line 324 "Parser.rl" -// line 347 "Parser.java" +// line 306 "Parser.java" private static byte[] init__JSON_value_actions_0() { return new byte [] { @@ -456,7 +416,7 @@ static final int JSON_value_error = 0; static final int JSON_value_en_main = 1; -// line 471 "Parser.rl" +// line 430 "Parser.rl" void parseValue(ParserResult res, int p, int pe) { @@ -464,14 +424,14 @@ static final int JSON_value_en_main = 1; IRubyObject result = null; -// line 469 "Parser.java" +// line 428 "Parser.java" { cs = JSON_value_start; } -// line 478 "Parser.rl" +// line 437 "Parser.rl" -// line 476 "Parser.java" +// line 435 "Parser.java" { int _klen; int _trans = 0; @@ -497,13 +457,13 @@ case 1: while ( _nacts-- > 0 ) { switch ( _JSON_value_actions[_acts++] ) { case 9: -// line 456 "Parser.rl" +// line 415 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 508 "Parser.java" +// line 467 "Parser.java" } } @@ -566,25 +526,25 @@ case 1: switch ( _JSON_value_actions[_acts++] ) { case 0: -// line 373 "Parser.rl" +// line 332 "Parser.rl" { result = getRuntime().getNil(); } break; case 1: -// line 376 "Parser.rl" +// line 335 "Parser.rl" { result = getRuntime().getFalse(); } break; case 2: -// line 379 "Parser.rl" +// line 338 "Parser.rl" { result = getRuntime().getTrue(); } break; case 3: -// line 382 "Parser.rl" +// line 341 "Parser.rl" { if (parser.allowNaN) { result = getConstant(CONST_NAN); @@ -594,7 +554,7 @@ case 1: } break; case 4: -// line 389 "Parser.rl" +// line 348 "Parser.rl" { if (parser.allowNaN) { result = getConstant(CONST_INFINITY); @@ -604,9 +564,9 @@ case 1: } break; case 5: -// line 396 "Parser.rl" +// line 355 "Parser.rl" { - if (pe > p + 9 - (parser.quirksMode ? 1 : 0) && + if (pe > p + 8 && absSubSequence(p, p + 9).equals(JSON_MINUS_INFINITY)) { if (parser.allowNaN) { @@ -633,7 +593,7 @@ case 1: } break; case 6: -// line 422 "Parser.rl" +// line 381 "Parser.rl" { parseString(res, p, pe); if (res.result == null) { @@ -646,7 +606,7 @@ case 1: } break; case 7: -// line 432 "Parser.rl" +// line 391 "Parser.rl" { currentNesting++; parseArray(res, p, pe); @@ -661,7 +621,7 @@ case 1: } break; case 8: -// line 444 "Parser.rl" +// line 403 "Parser.rl" { currentNesting++; parseObject(res, p, pe); @@ -675,7 +635,7 @@ case 1: } } break; -// line 680 "Parser.java" +// line 639 "Parser.java" } } } @@ -695,7 +655,7 @@ case 5: break; } } -// line 479 "Parser.rl" +// line 438 "Parser.rl" if (cs >= JSON_value_first_final && result != null) { res.update(result, p); @@ -705,7 +665,7 @@ case 5: } -// line 710 "Parser.java" +// line 669 "Parser.java" private static byte[] init__JSON_integer_actions_0() { return new byte [] { @@ -804,7 +764,7 @@ static final int JSON_integer_error = 0; static final int JSON_integer_en_main = 1; -// line 498 "Parser.rl" +// line 457 "Parser.rl" void parseInteger(ParserResult res, int p, int pe) { @@ -822,15 +782,15 @@ static final int JSON_integer_en_main = 1; int cs = EVIL; -// line 827 "Parser.java" +// line 786 "Parser.java" { cs = JSON_integer_start; } -// line 515 "Parser.rl" +// line 474 "Parser.rl" int memo = p; -// line 835 "Parser.java" +// line 794 "Parser.java" { int _klen; int _trans = 0; @@ -911,13 +871,13 @@ case 1: switch ( _JSON_integer_actions[_acts++] ) { case 0: -// line 492 "Parser.rl" +// line 451 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 922 "Parser.java" +// line 881 "Parser.java" } } } @@ -937,7 +897,7 @@ case 5: break; } } -// line 517 "Parser.rl" +// line 476 "Parser.rl" if (cs < JSON_integer_first_final) { return -1; @@ -959,7 +919,7 @@ case 5: } -// line 964 "Parser.java" +// line 923 "Parser.java" private static byte[] init__JSON_float_actions_0() { return new byte [] { @@ -1061,7 +1021,7 @@ static final int JSON_float_error = 0; static final int JSON_float_en_main = 1; -// line 552 "Parser.rl" +// line 511 "Parser.rl" void parseFloat(ParserResult res, int p, int pe) { @@ -1079,15 +1039,15 @@ static final int JSON_float_en_main = 1; int cs = EVIL; -// line 1084 "Parser.java" +// line 1043 "Parser.java" { cs = JSON_float_start; } -// line 569 "Parser.rl" +// line 528 "Parser.rl" int memo = p; -// line 1092 "Parser.java" +// line 1051 "Parser.java" { int _klen; int _trans = 0; @@ -1168,13 +1128,13 @@ case 1: switch ( _JSON_float_actions[_acts++] ) { case 0: -// line 543 "Parser.rl" +// line 502 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 1179 "Parser.java" +// line 1138 "Parser.java" } } } @@ -1194,7 +1154,7 @@ case 5: break; } } -// line 571 "Parser.rl" +// line 530 "Parser.rl" if (cs < JSON_float_first_final) { return -1; @@ -1210,7 +1170,7 @@ case 5: } -// line 1215 "Parser.java" +// line 1174 "Parser.java" private static byte[] init__JSON_string_actions_0() { return new byte [] { @@ -1312,7 +1272,7 @@ static final int JSON_string_error = 0; static final int JSON_string_en_main = 1; -// line 616 "Parser.rl" +// line 575 "Parser.rl" void parseString(ParserResult res, int p, int pe) { @@ -1320,15 +1280,15 @@ static final int JSON_string_en_main = 1; IRubyObject result = null; -// line 1325 "Parser.java" +// line 1284 "Parser.java" { cs = JSON_string_start; } -// line 623 "Parser.rl" +// line 582 "Parser.rl" int memo = p; -// line 1333 "Parser.java" +// line 1292 "Parser.java" { int _klen; int _trans = 0; @@ -1409,7 +1369,7 @@ case 1: switch ( _JSON_string_actions[_acts++] ) { case 0: -// line 591 "Parser.rl" +// line 550 "Parser.rl" { int offset = byteList.begin(); ByteList decoded = decoder.decode(byteList, memo + 1 - offset, @@ -1424,13 +1384,13 @@ case 1: } break; case 1: -// line 604 "Parser.rl" +// line 563 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 1435 "Parser.java" +// line 1394 "Parser.java" } } } @@ -1450,14 +1410,14 @@ case 5: break; } } -// line 625 "Parser.rl" +// line 584 "Parser.rl" if (parser.createAdditions) { - RubyHash match_string = parser.match_string; - if (match_string != null) { + RubyHash matchString = parser.matchString; + if (matchString != null) { final IRubyObject[] memoArray = { result, null }; try { - match_string.visitAll(new RubyHash.Visitor() { + matchString.visitAll(new RubyHash.Visitor() { @Override public void visit(IRubyObject pattern, IRubyObject klass) { if (pattern.callMethod(context, "===", memoArray[0]).isTrue()) { @@ -1478,7 +1438,7 @@ case 5: } if (cs >= JSON_string_first_final && result != null) { - if (info.encodingsSupported() && result instanceof RubyString) { + if (result instanceof RubyString) { ((RubyString)result).force_encoding(context, info.utf8.get()); } res.update(result, p + 1); @@ -1488,7 +1448,7 @@ case 5: } -// line 1493 "Parser.java" +// line 1452 "Parser.java" private static byte[] init__JSON_array_actions_0() { return new byte [] { @@ -1601,7 +1561,7 @@ static final int JSON_array_error = 0; static final int JSON_array_en_main = 1; -// line 698 "Parser.rl" +// line 657 "Parser.rl" void parseArray(ParserResult res, int p, int pe) { @@ -1621,14 +1581,14 @@ static final int JSON_array_en_main = 1; } -// line 1626 "Parser.java" +// line 1585 "Parser.java" { cs = JSON_array_start; } -// line 717 "Parser.rl" +// line 676 "Parser.rl" -// line 1633 "Parser.java" +// line 1592 "Parser.java" { int _klen; int _trans = 0; @@ -1709,7 +1669,7 @@ case 1: switch ( _JSON_array_actions[_acts++] ) { case 0: -// line 667 "Parser.rl" +// line 626 "Parser.rl" { parseValue(res, p, pe); if (res.result == null) { @@ -1726,13 +1686,13 @@ case 1: } break; case 1: -// line 682 "Parser.rl" +// line 641 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 1737 "Parser.java" +// line 1696 "Parser.java" } } } @@ -1752,7 +1712,7 @@ case 5: break; } } -// line 718 "Parser.rl" +// line 677 "Parser.rl" if (cs >= JSON_array_first_final) { res.update(result, p + 1); @@ -1762,7 +1722,7 @@ case 5: } -// line 1767 "Parser.java" +// line 1726 "Parser.java" private static byte[] init__JSON_object_actions_0() { return new byte [] { @@ -1885,7 +1845,7 @@ static final int JSON_object_error = 0; static final int JSON_object_en_main = 1; -// line 777 "Parser.rl" +// line 736 "Parser.rl" void parseObject(ParserResult res, int p, int pe) { @@ -1910,14 +1870,14 @@ static final int JSON_object_en_main = 1; } -// line 1915 "Parser.java" +// line 1874 "Parser.java" { cs = JSON_object_start; } -// line 801 "Parser.rl" +// line 760 "Parser.rl" -// line 1922 "Parser.java" +// line 1881 "Parser.java" { int _klen; int _trans = 0; @@ -1998,7 +1958,7 @@ case 1: switch ( _JSON_object_actions[_acts++] ) { case 0: -// line 732 "Parser.rl" +// line 691 "Parser.rl" { parseValue(res, p, pe); if (res.result == null) { @@ -2015,7 +1975,7 @@ case 1: } break; case 1: -// line 747 "Parser.rl" +// line 706 "Parser.rl" { parseString(res, p, pe); if (res.result == null) { @@ -2035,13 +1995,13 @@ case 1: } break; case 2: -// line 765 "Parser.rl" +// line 724 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 2046 "Parser.java" +// line 2005 "Parser.java" } } } @@ -2061,7 +2021,7 @@ case 5: break; } } -// line 802 "Parser.rl" +// line 761 "Parser.rl" if (cs < JSON_object_first_final) { res.update(null, p + 1); @@ -2094,11 +2054,11 @@ case 5: } -// line 2099 "Parser.java" +// line 2058 "Parser.java" private static byte[] init__JSON_actions_0() { return new byte [] { - 0, 1, 0, 1, 1 + 0, 1, 0 }; } @@ -2108,7 +2068,7 @@ private static final byte _JSON_actions[] = init__JSON_actions_0(); private static byte[] init__JSON_key_offsets_0() { return new byte [] { - 0, 0, 7, 9, 10, 12, 13, 15, 16, 18, 19 + 0, 0, 16, 18, 19, 21, 22, 24, 25, 27, 28 }; } @@ -2118,9 +2078,9 @@ private static final byte _JSON_key_offsets[] = init__JSON_key_offsets_0(); private static char[] init__JSON_trans_keys_0() { return new char [] { - 13, 32, 47, 91, 123, 9, 10, 42, 47, 42, 42, 47, - 10, 42, 47, 42, 42, 47, 10, 13, 32, 47, 9, 10, - 0 + 13, 32, 34, 45, 47, 73, 78, 91, 102, 110, 116, 123, + 9, 10, 48, 57, 42, 47, 42, 42, 47, 10, 42, 47, + 42, 42, 47, 10, 13, 32, 47, 9, 10, 0 }; } @@ -2130,7 +2090,7 @@ private static final char _JSON_trans_keys[] = init__JSON_trans_keys_0(); private static byte[] init__JSON_single_lengths_0() { return new byte [] { - 0, 5, 2, 1, 2, 1, 2, 1, 2, 1, 3 + 0, 12, 2, 1, 2, 1, 2, 1, 2, 1, 3 }; } @@ -2140,7 +2100,7 @@ private static final byte _JSON_single_lengths[] = init__JSON_single_lengths_0() private static byte[] init__JSON_range_lengths_0() { return new byte [] { - 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 + 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; } @@ -2150,7 +2110,7 @@ private static final byte _JSON_range_lengths[] = init__JSON_range_lengths_0(); private static byte[] init__JSON_index_offsets_0() { return new byte [] { - 0, 0, 7, 10, 12, 15, 17, 20, 22, 25, 27 + 0, 0, 15, 18, 20, 23, 25, 28, 30, 33, 35 }; } @@ -2160,9 +2120,10 @@ private static final byte _JSON_index_offsets[] = init__JSON_index_offsets_0(); private static byte[] init__JSON_indicies_0() { return new byte [] { - 0, 0, 2, 3, 4, 0, 1, 5, 6, 1, 7, 5, - 7, 0, 5, 0, 6, 8, 9, 1, 10, 8, 10, 11, - 8, 11, 9, 11, 11, 12, 11, 1, 0 + 0, 0, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, + 0, 2, 1, 4, 5, 1, 6, 4, 6, 7, 4, 7, + 5, 8, 9, 1, 10, 8, 10, 0, 8, 0, 9, 7, + 7, 11, 7, 1, 0 }; } @@ -2172,8 +2133,7 @@ private static final byte _JSON_indicies[] = init__JSON_indicies_0(); private static byte[] init__JSON_trans_targs_0() { return new byte [] { - 1, 0, 2, 10, 10, 3, 5, 4, 7, 9, 8, 10, - 6 + 1, 0, 10, 6, 3, 5, 4, 10, 7, 9, 8, 2 }; } @@ -2183,8 +2143,7 @@ private static final byte _JSON_trans_targs[] = init__JSON_trans_targs_0(); private static byte[] init__JSON_trans_actions_0() { return new byte [] { - 0, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0, 0, - 0 + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; } @@ -2198,26 +2157,26 @@ static final int JSON_error = 0; static final int JSON_en_main = 1; -// line 867 "Parser.rl" +// line 812 "Parser.rl" - public IRubyObject parseStrict() { + public IRubyObject parseImplemetation() { int cs = EVIL; int p, pe; IRubyObject result = null; ParserResult res = new ParserResult(); -// line 2213 "Parser.java" +// line 2171 "Parser.java" { cs = JSON_start; } -// line 876 "Parser.rl" +// line 821 "Parser.rl" p = byteList.begin(); pe = p + byteList.length(); -// line 2222 "Parser.java" +// line 2180 "Parser.java" { int _klen; int _trans = 0; @@ -2298,267 +2257,7 @@ case 1: switch ( _JSON_actions[_acts++] ) { case 0: -// line 839 "Parser.rl" - { - currentNesting = 1; - parseObject(res, p, pe); - if (res.result == null) { - p--; - { p += 1; _goto_targ = 5; if (true) continue _goto;} - } else { - result = res.result; - {p = (( res.p))-1;} - } - } - break; - case 1: -// line 851 "Parser.rl" - { - currentNesting = 1; - parseArray(res, p, pe); - if (res.result == null) { - p--; - { p += 1; _goto_targ = 5; if (true) continue _goto;} - } else { - result = res.result; - {p = (( res.p))-1;} - } - } - break; -// line 2330 "Parser.java" - } - } - } - -case 2: - if ( cs == 0 ) { - _goto_targ = 5; - continue _goto; - } - if ( ++p != pe ) { - _goto_targ = 1; - continue _goto; - } -case 4: -case 5: - } - break; } - } - -// line 879 "Parser.rl" - - if (cs >= JSON_first_final && p == pe) { - return result; - } else { - throw unexpectedToken(p, pe); - } - } - - -// line 2360 "Parser.java" -private static byte[] init__JSON_quirks_mode_actions_0() -{ - return new byte [] { - 0, 1, 0 - }; -} - -private static final byte _JSON_quirks_mode_actions[] = init__JSON_quirks_mode_actions_0(); - - -private static byte[] init__JSON_quirks_mode_key_offsets_0() -{ - return new byte [] { - 0, 0, 16, 18, 19, 21, 22, 24, 25, 27, 28 - }; -} - -private static final byte _JSON_quirks_mode_key_offsets[] = init__JSON_quirks_mode_key_offsets_0(); - - -private static char[] init__JSON_quirks_mode_trans_keys_0() -{ - return new char [] { - 13, 32, 34, 45, 47, 73, 78, 91, 102, 110, 116, 123, - 9, 10, 48, 57, 42, 47, 42, 42, 47, 10, 42, 47, - 42, 42, 47, 10, 13, 32, 47, 9, 10, 0 - }; -} - -private static final char _JSON_quirks_mode_trans_keys[] = init__JSON_quirks_mode_trans_keys_0(); - - -private static byte[] init__JSON_quirks_mode_single_lengths_0() -{ - return new byte [] { - 0, 12, 2, 1, 2, 1, 2, 1, 2, 1, 3 - }; -} - -private static final byte _JSON_quirks_mode_single_lengths[] = init__JSON_quirks_mode_single_lengths_0(); - - -private static byte[] init__JSON_quirks_mode_range_lengths_0() -{ - return new byte [] { - 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1 - }; -} - -private static final byte _JSON_quirks_mode_range_lengths[] = init__JSON_quirks_mode_range_lengths_0(); - - -private static byte[] init__JSON_quirks_mode_index_offsets_0() -{ - return new byte [] { - 0, 0, 15, 18, 20, 23, 25, 28, 30, 33, 35 - }; -} - -private static final byte _JSON_quirks_mode_index_offsets[] = init__JSON_quirks_mode_index_offsets_0(); - - -private static byte[] init__JSON_quirks_mode_indicies_0() -{ - return new byte [] { - 0, 0, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, - 0, 2, 1, 4, 5, 1, 6, 4, 6, 7, 4, 7, - 5, 8, 9, 1, 10, 8, 10, 0, 8, 0, 9, 7, - 7, 11, 7, 1, 0 - }; -} - -private static final byte _JSON_quirks_mode_indicies[] = init__JSON_quirks_mode_indicies_0(); - - -private static byte[] init__JSON_quirks_mode_trans_targs_0() -{ - return new byte [] { - 1, 0, 10, 6, 3, 5, 4, 10, 7, 9, 8, 2 - }; -} - -private static final byte _JSON_quirks_mode_trans_targs[] = init__JSON_quirks_mode_trans_targs_0(); - - -private static byte[] init__JSON_quirks_mode_trans_actions_0() -{ - return new byte [] { - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; -} - -private static final byte _JSON_quirks_mode_trans_actions[] = init__JSON_quirks_mode_trans_actions_0(); - - -static final int JSON_quirks_mode_start = 1; -static final int JSON_quirks_mode_first_final = 10; -static final int JSON_quirks_mode_error = 0; - -static final int JSON_quirks_mode_en_main = 1; - - -// line 907 "Parser.rl" - - - public IRubyObject parseQuirksMode() { - int cs = EVIL; - int p, pe; - IRubyObject result = null; - ParserResult res = new ParserResult(); - - -// line 2473 "Parser.java" - { - cs = JSON_quirks_mode_start; - } - -// line 916 "Parser.rl" - p = byteList.begin(); - pe = p + byteList.length(); - -// line 2482 "Parser.java" - { - int _klen; - int _trans = 0; - int _acts; - int _nacts; - int _keys; - int _goto_targ = 0; - - _goto: while (true) { - switch ( _goto_targ ) { - case 0: - if ( p == pe ) { - _goto_targ = 4; - continue _goto; - } - if ( cs == 0 ) { - _goto_targ = 5; - continue _goto; - } -case 1: - _match: do { - _keys = _JSON_quirks_mode_key_offsets[cs]; - _trans = _JSON_quirks_mode_index_offsets[cs]; - _klen = _JSON_quirks_mode_single_lengths[cs]; - if ( _klen > 0 ) { - int _lower = _keys; - int _mid; - int _upper = _keys + _klen - 1; - while (true) { - if ( _upper < _lower ) - break; - - _mid = _lower + ((_upper-_lower) >> 1); - if ( data[p] < _JSON_quirks_mode_trans_keys[_mid] ) - _upper = _mid - 1; - else if ( data[p] > _JSON_quirks_mode_trans_keys[_mid] ) - _lower = _mid + 1; - else { - _trans += (_mid - _keys); - break _match; - } - } - _keys += _klen; - _trans += _klen; - } - - _klen = _JSON_quirks_mode_range_lengths[cs]; - if ( _klen > 0 ) { - int _lower = _keys; - int _mid; - int _upper = _keys + (_klen<<1) - 2; - while (true) { - if ( _upper < _lower ) - break; - - _mid = _lower + (((_upper-_lower) >> 1) & ~1); - if ( data[p] < _JSON_quirks_mode_trans_keys[_mid] ) - _upper = _mid - 2; - else if ( data[p] > _JSON_quirks_mode_trans_keys[_mid+1] ) - _lower = _mid + 2; - else { - _trans += ((_mid - _keys)>>1); - break _match; - } - } - _trans += _klen; - } - } while (false); - - _trans = _JSON_quirks_mode_indicies[_trans]; - cs = _JSON_quirks_mode_trans_targs[_trans]; - - if ( _JSON_quirks_mode_trans_actions[_trans] != 0 ) { - _acts = _JSON_quirks_mode_trans_actions[_trans]; - _nacts = (int) _JSON_quirks_mode_actions[_acts++]; - while ( _nacts-- > 0 ) - { - switch ( _JSON_quirks_mode_actions[_acts++] ) - { - case 0: -// line 893 "Parser.rl" +// line 798 "Parser.rl" { parseValue(res, p, pe); if (res.result == null) { @@ -2570,7 +2269,7 @@ case 1: } } break; -// line 2575 "Parser.java" +// line 2273 "Parser.java" } } } @@ -2590,9 +2289,9 @@ case 5: break; } } -// line 919 "Parser.rl" +// line 824 "Parser.rl" - if (cs >= JSON_quirks_mode_first_final && p == pe) { + if (cs >= JSON_first_final && p == pe) { return result; } else { throw unexpectedToken(p, pe); @@ -2600,12 +2299,7 @@ case 5: } public IRubyObject parse() { - if (parser.quirksMode) { - return parseQuirksMode(); - } else { - return parseStrict(); - } - + return parseImplemetation(); } /** diff --git a/java/src/json/ext/Parser.rl b/java/src/json/ext/Parser.rl index d43c74f..17ea303 100644 --- a/java/src/json/ext/Parser.rl +++ b/java/src/json/ext/Parser.rl @@ -50,10 +50,9 @@ public class Parser extends RubyObject { private int maxNesting; private boolean allowNaN; private boolean symbolizeNames; - private boolean quirksMode; private RubyClass objectClass; private RubyClass arrayClass; - private RubyHash match_string; + private RubyHash matchString; private static final int DEFAULT_MAX_NESTING = 100; @@ -121,10 +120,6 @@ public class Parser extends RubyObject { *

If set to true, returns symbols for the names (keys) in * a JSON object. Otherwise strings are returned, which is also the default. * - *
:quirks_mode? - *
If set to true, if the parse is in quirks_mode, false - * otherwise. - * *
:create_additions *
If set to false, the Parser doesn't create additions * even if a matching class and create_id was found. This option @@ -136,9 +131,6 @@ public class Parser extends RubyObject { *
:array_class *
Defaults to Array. * - *
:quirks_mode - *
Enables quirks_mode for parser, that is for example parsing single - * JSON values instead of documents is possible. * */ @JRubyMethod(name = "new", required = 1, optional = 1, meta = true) @@ -161,15 +153,20 @@ public class Parser extends RubyObject { this.maxNesting = opts.getInt("max_nesting", DEFAULT_MAX_NESTING); this.allowNaN = opts.getBool("allow_nan", false); this.symbolizeNames = opts.getBool("symbolize_names", false); - this.quirksMode = opts.getBool("quirks_mode", false); this.createId = opts.getString("create_id", getCreateId(context)); this.createAdditions = opts.getBool("create_additions", false); this.objectClass = opts.getClass("object_class", runtime.getHash()); this.arrayClass = opts.getClass("array_class", runtime.getArray()); - this.match_string = opts.getHash("match_string"); + this.matchString = opts.getHash("match_string"); + if(symbolizeNames && createAdditions) { + throw runtime.newArgumentError( + "options :symbolize_names and :create_additions cannot be " + + " used in conjunction" + ); + } this.vSource = args[0].convertToString(); - if (!quirksMode) this.vSource = convertEncoding(context, vSource); + this.vSource = convertEncoding(context, vSource); return this; } @@ -180,33 +177,7 @@ public class Parser extends RubyObject { * Returns the source string if no conversion is needed. */ private RubyString convertEncoding(ThreadContext context, RubyString source) { - ByteList bl = source.getByteList(); - int len = bl.length(); - if (len < 2) { - throw Utils.newException(context, Utils.M_PARSER_ERROR, - "A JSON text must at least contain two octets!"); - } - - if (info.encodingsSupported()) { - RubyEncoding encoding = (RubyEncoding)source.encoding(context); - if (encoding != info.ascii8bit.get()) { - return (RubyString)source.encode(context, info.utf8.get()); - } - - String sniffedEncoding = sniffByteList(bl); - if (sniffedEncoding == null) return source; // assume UTF-8 - return reinterpretEncoding(context, source, sniffedEncoding); - } - - String sniffedEncoding = sniffByteList(bl); - if (sniffedEncoding == null) return source; // assume UTF-8 - Ruby runtime = context.getRuntime(); - return (RubyString)info.jsonModule.get(). - callMethod(context, "iconv", - new IRubyObject[] { - runtime.newString("utf-8"), - runtime.newString(sniffedEncoding), - source}); + return (RubyString)source.encode(context, info.utf8.get()); } /** @@ -259,17 +230,6 @@ public class Parser extends RubyObject { return checkAndGetSource().dup(); } - /** - * Parser#quirks_mode?() - * - *

If set to true, if the parse is in quirks_mode, false - * otherwise. - */ - @JRubyMethod(name = "quirks_mode?") - public IRubyObject quirks_mode_p(ThreadContext context) { - return context.getRuntime().newBoolean(quirksMode); - } - public RubyString checkAndGetSource() { if (vSource != null) { return vSource; @@ -393,7 +353,7 @@ public class Parser extends RubyObject { } } action parse_number { - if (pe > fpc + 9 - (parser.quirksMode ? 1 : 0) && + if (pe > fpc + 8 && absSubSequence(fpc, fpc + 9).equals(JSON_MINUS_INFINITY)) { if (parser.allowNaN) { @@ -623,11 +583,11 @@ public class Parser extends RubyObject { %% write exec; if (parser.createAdditions) { - RubyHash match_string = parser.match_string; - if (match_string != null) { + RubyHash matchString = parser.matchString; + if (matchString != null) { final IRubyObject[] memoArray = { result, null }; try { - match_string.visitAll(new RubyHash.Visitor() { + matchString.visitAll(new RubyHash.Visitor() { @Override public void visit(IRubyObject pattern, IRubyObject klass) { if (pattern.callMethod(context, "===", memoArray[0]).isTrue()) { @@ -648,7 +608,7 @@ public class Parser extends RubyObject { } if (cs >= JSON_string_first_final && result != null) { - if (info.encodingsSupported() && result instanceof RubyString) { + if (result instanceof RubyString) { ((RubyString)result).force_encoding(context, info.utf8.get()); } res.update(result, p + 1); @@ -835,60 +795,6 @@ public class Parser extends RubyObject { write data; - action parse_object { - currentNesting = 1; - parseObject(res, fpc, pe); - if (res.result == null) { - fhold; - fbreak; - } else { - result = res.result; - fexec res.p; - } - } - - action parse_array { - currentNesting = 1; - parseArray(res, fpc, pe); - if (res.result == null) { - fhold; - fbreak; - } else { - result = res.result; - fexec res.p; - } - } - - main := ignore* - ( begin_object >parse_object - | begin_array >parse_array ) - ignore*; - }%% - - public IRubyObject parseStrict() { - int cs = EVIL; - int p, pe; - IRubyObject result = null; - ParserResult res = new ParserResult(); - - %% write init; - p = byteList.begin(); - pe = p + byteList.length(); - %% write exec; - - if (cs >= JSON_first_final && p == pe) { - return result; - } else { - throw unexpectedToken(p, pe); - } - } - - %%{ - machine JSON_quirks_mode; - include JSON_common; - - write data; - action parse_value { parseValue(res, fpc, pe); if (res.result == null) { @@ -905,7 +811,7 @@ public class Parser extends RubyObject { ignore*; }%% - public IRubyObject parseQuirksMode() { + public IRubyObject parseImplemetation() { int cs = EVIL; int p, pe; IRubyObject result = null; @@ -916,7 +822,7 @@ public class Parser extends RubyObject { pe = p + byteList.length(); %% write exec; - if (cs >= JSON_quirks_mode_first_final && p == pe) { + if (cs >= JSON_first_final && p == pe) { return result; } else { throw unexpectedToken(p, pe); @@ -924,12 +830,7 @@ public class Parser extends RubyObject { } public IRubyObject parse() { - if (parser.quirksMode) { - return parseQuirksMode(); - } else { - return parseStrict(); - } - + return parseImplemetation(); } /** diff --git a/java/src/json/ext/RuntimeInfo.java b/java/src/json/ext/RuntimeInfo.java index ceaca5b..2323bd9 100644 --- a/java/src/json/ext/RuntimeInfo.java +++ b/java/src/json/ext/RuntimeInfo.java @@ -90,10 +90,6 @@ final class RuntimeInfo { } } - public boolean encodingsSupported() { - return utf8 != null && utf8.get() != null; - } - public RubyEncoding getEncoding(ThreadContext context, String name) { synchronized (encodings) { WeakReference encoding = encodings.get(name); diff --git a/json.gemspec b/json.gemspec index a9493ff..e6b4afd 100644 Binary files a/json.gemspec and b/json.gemspec differ diff --git a/json_pure.gemspec b/json_pure.gemspec index 13c8e8b..a93dbf9 100644 --- a/json_pure.gemspec +++ b/json_pure.gemspec @@ -8,11 +8,11 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.require_paths = ["lib"] s.authors = ["Florian Frank"] - s.date = "2016-02-25" + s.date = "2016-06-02" s.description = "This is a JSON implementation in pure Ruby." s.email = "flori@ping.de" s.extra_rdoc_files = ["README.md"] - s.files = ["./tests/test_helper.rb", ".gitignore", ".travis.yml", "CHANGES", "Gemfile", "README-json-jruby.markdown", "README.md", "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/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/obsolete_fail1.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/json_addition_test.rb", "tests/json_common_interface_test.rb", "tests/json_encoding_test.rb", "tests/json_ext_parser_test.rb", "tests/json_fixtures_test.rb", "tests/json_generator_test.rb", "tests/json_generic_object_test.rb", "tests/json_parser_test.rb", "tests/json_string_matching_test.rb", "tests/test_helper.rb", "tools/fuzz.rb", "tools/server.rb"] + s.files = ["./tests/test_helper.rb", ".gitignore", ".travis.yml", "CHANGES", "Gemfile", "README-json-jruby.markdown", "README.md", "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", "references/rfc7159.txt", "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/obsolete_fail1.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/json_addition_test.rb", "tests/json_common_interface_test.rb", "tests/json_encoding_test.rb", "tests/json_ext_parser_test.rb", "tests/json_fixtures_test.rb", "tests/json_generator_test.rb", "tests/json_generic_object_test.rb", "tests/json_parser_test.rb", "tests/json_string_matching_test.rb", "tests/test_helper.rb", "tools/fuzz.rb", "tools/server.rb"] s.homepage = "http://flori.github.com/json" s.licenses = ["Ruby"] s.rdoc_options = ["--title", "JSON implemention for ruby", "--main", "README.md"] diff --git a/lib/json/common.rb b/lib/json/common.rb index c47938f..209c3e7 100644 --- a/lib/json/common.rb +++ b/lib/json/common.rb @@ -295,13 +295,13 @@ module JSON # The global default options for the JSON.load method: # :max_nesting: false # :allow_nan: true - # :quirks_mode: true + # :allow_null: true attr_accessor :load_default_options end self.load_default_options = { :max_nesting => false, :allow_nan => true, - :quirks_mode => true, + :allow_null => true, :create_additions => true, } @@ -328,7 +328,7 @@ module JSON elsif source.respond_to?(:read) source = source.read end - if opts[:quirks_mode] && (source.nil? || source.empty?) + if opts[:allow_null] && (source.nil? || source.empty?) source = 'null' end result = parse(source, opts) @@ -357,13 +357,12 @@ module JSON # The global default options for the JSON.dump method: # :max_nesting: false # :allow_nan: true - # :quirks_mode: true + # :allow_null: true attr_accessor :dump_default_options end self.dump_default_options = { :max_nesting => false, :allow_nan => true, - :quirks_mode => true, } # Dumps _obj_ as a JSON string, i.e. calls generate on the object and returns diff --git a/lib/json/pure/generator.rb b/lib/json/pure/generator.rb index cc8b0fd..cf4afff 100644 --- a/lib/json/pure/generator.rb +++ b/lib/json/pure/generator.rb @@ -154,8 +154,6 @@ module JSON # * *allow_nan*: true if NaN, Infinity, and -Infinity should be # generated, otherwise an exception is thrown, if these values are # encountered. This options defaults to false. - # * *quirks_mode*: Enables quirks_mode for parser, that is for example - # generating single JSON values instead of documents is possible. def initialize(opts = {}) @indent = '' @space = '' @@ -164,7 +162,6 @@ module JSON @array_nl = '' @allow_nan = false @ascii_only = false - @quirks_mode = false @buffer_initial_length = 1024 configure opts end @@ -190,10 +187,6 @@ module JSON # the generated JSON, max_nesting = 0 if no maximum is checked. attr_accessor :max_nesting - # If this attribute is set to true, quirks mode is enabled, otherwise - # it's disabled. - attr_accessor :quirks_mode - # :stopdoc: attr_reader :buffer_initial_length @@ -233,11 +226,6 @@ module JSON @ascii_only end - # Returns true, if quirks mode is enabled. Otherwise returns false. - def quirks_mode? - @quirks_mode - end - # Configure this State instance with the Hash _opts_, and return # itself. def configure(opts) @@ -259,7 +247,6 @@ module JSON @allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan) @ascii_only = opts[:ascii_only] if opts.key?(:ascii_only) @depth = opts[:depth] || 0 - @quirks_mode = opts[:quirks_mode] if opts.key?(:quirks_mode) @buffer_initial_length ||= opts[:buffer_initial_length] if !opts.key?(:max_nesting) # defaults to 100 diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb index c96fadb..b2e841b 100644 --- a/lib/json/pure/parser.rb +++ b/lib/json/pure/parser.rb @@ -69,13 +69,9 @@ module JSON # option defaults to false. # * *object_class*: Defaults to Hash # * *array_class*: Defaults to Array - # * *quirks_mode*: Enables quirks_mode for parser, that is for example - # parsing single JSON values instead of documents is possible. def initialize(source, opts = {}) opts ||= {} - unless @quirks_mode = opts[:quirks_mode] - source = convert_encoding source - end + source = convert_encoding source super source if !opts.key?(:max_nesting) # defaults to 100 @max_nesting = 100 @@ -102,10 +98,6 @@ module JSON alias source string - def quirks_mode? - !!@quirks_mode - end - def reset super @current_nesting = 0 @@ -138,10 +130,8 @@ module JSON raise TypeError, "#{source.inspect} is not like a string" end - if defined?(::Encoding) - source = source.encode(::Encoding::UTF_8) - source.force_encoding(::Encoding::ASCII_8BIT) - end + source = source.encode(::Encoding::UTF_8) + source.force_encoding(::Encoding::ASCII_8BIT) source end diff --git a/tests/json_common_interface_test.rb b/tests/json_common_interface_test.rb index 6485328..382c77b 100644 --- a/tests/json_common_interface_test.rb +++ b/tests/json_common_interface_test.rb @@ -70,6 +70,12 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase assert JSON.load(json, nil, :allow_nan => true)['foo'].nan? end + def test_load_null + assert_equal nil, JSON.load(nil, nil, :allow_null => true) + assert_raises(TypeError) { JSON.load(nil, nil, :allow_null => false) } + assert_raises(JSON::ParserError) { JSON.load('', nil, :allow_null => false) } + end + def test_dump too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]' assert_equal too_deep, dump(eval(too_deep)) @@ -92,7 +98,6 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase assert_equal max_nesting, JSON.dump_default_options[:max_nesting] end - def test_JSON end end diff --git a/tests/json_generator_test.rb b/tests/json_generator_test.rb index 2bb7e15..75e19d9 100644 --- a/tests/json_generator_test.rb +++ b/tests/json_generator_test.rb @@ -135,7 +135,6 @@ EOT :array_nl => "\n", :ascii_only => false, :buffer_initial_length => 1024, - :quirks_mode => false, :depth => 0, :indent => " ", :max_nesting => 100, @@ -152,7 +151,6 @@ EOT :array_nl => "", :ascii_only => false, :buffer_initial_length => 1024, - :quirks_mode => false, :depth => 0, :indent => "", :max_nesting => 100, @@ -169,7 +167,6 @@ EOT :array_nl => "", :ascii_only => false, :buffer_initial_length => 1024, - :quirks_mode => false, :depth => 0, :indent => "", :max_nesting => 0, diff --git a/tests/json_parser_test.rb b/tests/json_parser_test.rb index 1123aab..a5793f9 100644 --- a/tests/json_parser_test.rb +++ b/tests/json_parser_test.rb @@ -137,7 +137,7 @@ class JSONParserTest < Test::Unit::TestCase assert parse('NaN', :allow_nan => true).nan? assert parse('Infinity', :allow_nan => true).infinite? assert parse('-Infinity', :allow_nan => true).infinite? - assert_raise(JSON::ParserError) { parse('[ 1, ]', :quirks_mode => true) } + assert_raise(JSON::ParserError) { parse('[ 1, ]') } end def test_parse_some_strings diff --git a/tests/test_helper.rb b/tests/test_helper.rb index 9d3665d..752f5f5 100644 --- a/tests/test_helper.rb +++ b/tests/test_helper.rb @@ -17,7 +17,3 @@ begin require 'byebug' rescue LoadError end -if ENV['START_SIMPLECOV'].to_i == 1 - require 'simplecov' - SimpleCov.start -end -- cgit v1.2.1