ruby-changes:43503
From: hsbt <ko1@a...>
Date: Tue, 5 Jul 2016 20:49:45 +0900 (JST)
Subject: [ruby-changes:43503] hsbt:r55576 (trunk): * ext/json/*, test/json/*: Update json-2.0.1.
hsbt 2016-07-05 20:49:39 +0900 (Tue, 05 Jul 2016) New Revision: 55576 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55576 Log: * ext/json/*, test/json/*: Update json-2.0.1. Changes of 2.0.0: https://github.com/flori/json/blob/f679ebd0c69a94e3e70a897ac9a229f5779c2ee1/CHANGES.md#2015-09-11-200 Changes of 2.0.1: https://github.com/flori/json/blob/f679ebd0c69a94e3e70a897ac9a229f5779c2ee1/CHANGES.md#2016-07-01-201 [Feature #12542][ruby-dev:49706][fix GH-1395] Added directories: trunk/ext/json/lib/json/ext/ Added files: trunk/ext/json/lib/json/ext/.keep trunk/test/json/fixtures/obsolete_fail1.json trunk/test/json/test_helper.rb trunk/test/json/test_json_common_interface.rb trunk/test/json/test_json_ext_parser.rb trunk/test/json/test_json_generator.rb trunk/test/json/test_json_parser.rb Removed files: trunk/ext/json/parser/prereq.mk trunk/test/json/fixtures/fail1.json trunk/test/json/setup_variant.rb trunk/test/json/test_json.rb trunk/test/json/test_json_generate.rb trunk/test/json/test_json_unicode.rb Modified files: trunk/ChangeLog trunk/ext/json/generator/generator.c trunk/ext/json/generator/generator.h trunk/ext/json/json.gemspec trunk/ext/json/lib/json/common.rb trunk/ext/json/lib/json/ext.rb trunk/ext/json/lib/json/generic_object.rb trunk/ext/json/lib/json/version.rb trunk/ext/json/parser/parser.c trunk/ext/json/parser/parser.h trunk/ext/json/parser/parser.rl trunk/test/json/test_json_addition.rb trunk/test/json/test_json_encoding.rb trunk/test/json/test_json_fixtures.rb trunk/test/json/test_json_generic_object.rb trunk/test/json/test_json_string_matching.rb Index: ext/json/generator/generator.c =================================================================== --- ext/json/generator/generator.c (revision 55575) +++ ext/json/generator/generator.c (revision 55576) @@ -20,7 +20,7 @@ static VALUE mJSON, mExt, mGenerator, cS https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L20 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; @@ -222,6 +222,7 @@ static void convert_UTF8_to_JSON_ASCII(F https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L222 unicode_escape_to_buffer(buffer, buf, (UTF16)((ch & halfMask) + UNI_SUR_LOW_START)); } } + RB_GC_GUARD(string); } /* Converts string to a JSON string in FBuffer buffer, where only the @@ -641,8 +642,6 @@ static VALUE cState_configure(VALUE self https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L642 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; } @@ -676,7 +675,6 @@ static VALUE cState_to_h(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L675 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)); @@ -853,7 +851,6 @@ static void generate_json_integer(FBuffe https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L851 generate_json_bignum(buffer, Vstate, state, obj); } #endif - static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj) { double value = RFLOAT_VALUE(obj); @@ -944,21 +941,6 @@ static VALUE cState_partial_generate(VAL https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L941 } /* - * This function returns true if string is either a JSON array or JSON object. - * It might suffer from false positives, e. g. syntactically incorrect JSON in - * the string or certain UTF-8 characters on the right hand side. - */ -static int isArrayOrObject(VALUE string) -{ - long string_len = RSTRING_LEN(string); - char *p = RSTRING_PTR(string), *q = p + string_len - 1; - if (string_len < 2) return 0; - for (; p < q && isspace((unsigned char)*p); p++); - for (; q > p && isspace((unsigned char)*q); q--); - return (*p == '[' && *q == ']') || (*p == '{' && *q == '}'); -} - -/* * call-seq: generate(obj) * * Generates a valid JSON document from object +obj+ and returns the @@ -969,9 +951,6 @@ static VALUE cState_generate(VALUE self, https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L951 { VALUE result = cState_partial_generate(self, obj); GET_STATE(self); - if (!state->quirks_mode && !isArrayOrObject(result)) { - rb_raise(eGeneratorError, "only generation of JSON objects or arrays allowed"); - } return result; } @@ -990,8 +969,6 @@ static VALUE cState_generate(VALUE self, https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L969 * * *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. */ @@ -1299,29 +1276,6 @@ static VALUE cState_ascii_only_p(VALUE s https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L1276 } /* - * 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 * * This integer returns the current depth of data structure nesting. @@ -1409,9 +1363,6 @@ void Init_generator(void) https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L1363 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); @@ -1468,7 +1419,6 @@ void Init_generator(void) https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L1419 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"); Index: ext/json/generator/generator.h =================================================================== --- ext/json/generator/generator.h (revision 55575) +++ ext/json/generator/generator.h (revision 55576) @@ -73,7 +73,6 @@ typedef struct JSON_Generator_StateStruc https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.h#L73 long max_nesting; char allow_nan; char ascii_only; - char quirks_mode; long depth; long buffer_initial_length; } JSON_Generator_State; Index: ext/json/lib/json/ext/.keep =================================================================== Index: ext/json/lib/json/ext.rb =================================================================== --- ext/json/lib/json/ext.rb (revision 55575) +++ ext/json/lib/json/ext.rb (revision 55576) @@ -1,10 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/ext.rb#L1 # frozen_string_literal: false -if ENV['SIMPLECOV_COVERAGE'].to_i == 1 - require 'simplecov' - SimpleCov.start do - add_filter "/tests/" - end -end require 'json/common' module JSON Index: ext/json/lib/json/generic_object.rb =================================================================== --- ext/json/lib/json/generic_object.rb (revision 55575) +++ ext/json/lib/json/generic_object.rb (revision 55576) @@ -48,6 +48,14 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/generic_object.rb#L48 table end + def [](name) + __send__(name) + end unless method_defined?(:[]) + + def []=(name, value) + __send__("#{name}=", value) + end unless method_defined?(:[]=) + def |(other) self.class[other.to_hash.merge(to_hash)] end Index: ext/json/lib/json/version.rb =================================================================== --- ext/json/lib/json/version.rb (revision 55575) +++ ext/json/lib/json/version.rb (revision 55576) @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/version.rb#L1 # frozen_string_literal: false module JSON # JSON version - VERSION = '1.8.3' + VERSION = '2.0.1' VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc: VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc: VERSION_MINOR = VERSION_ARRAY[1] # :nodoc: Index: ext/json/lib/json/common.rb =================================================================== --- ext/json/lib/json/common.rb (revision 55575) +++ ext/json/lib/json/common.rb (revision 55576) @@ -4,12 +4,12 @@ require 'json/generic_object' https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L4 module JSON class << self - # If _object_ is string-like, parse the string and return the parsed result - # as a Ruby data structure. Otherwise generate a JSON text from the Ruby - # data structure object and return it. + # If _object_ is string-like, parse the string and return the parsed + # result as a Ruby data structure. Otherwise generate a JSON text from the + # Ruby data structure object and return it. # - # The _opts_ argument is passed through to generate/parse respectively. See - # generate and parse for their documentation. + # The _opts_ argument is passed through to generate/parse respectively. + # See generate and parse for their documentation. def [](object, opts = {}) if object.respond_to? :to_str JSON.parse(object.to_str, opts) @@ -25,7 +25,7 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L25 # Set the JSON parser class _parser_ to be used by JSON. def parser=(parser) # :nodoc: @parser = parser - remove_const :Parser if JSON.const_defined_in?(self, :Parser) + remove_const :Parser if const_defined?(:Parser, false) const_set :Parser, parser end @@ -36,8 +36,8 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L36 def deep_const_get(path) # :nodoc: path.to_s.split(/::/).inject(Object) do |p, c| case - when c.empty? then p - when JSON.const_defined_in?(p, c) then p.const_get(c) + when c.empty? then p + when p.const_defined?(c, true) then p.const_get(c) else begin p.const_missing(c) @@ -139,10 +139,10 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L139 # _opts_ can have the following # keys: # * *max_nesting*: The maximum depth of nesting allowed in the parsed data - # structures. Disable depth checking with :max_nesting => false. It defaults - # to 100. + # structures. Disable depth checking with :max_nesting => false. It + # defaults to 100. # * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in - # defiance of RFC 4627 to be parsed by the Parser. This option defaults + # defiance of RFC 7159 to be parsed by the Parser. This option defaults # to false. # * *symbolize_names*: If set to true, returns symbols for the names # (keys) in a JSON object. Otherwise strings are returned. Strings are @@ -162,11 +162,11 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L162 # # _opts_ can have the following keys: # * *max_nesting*: The maximum depth of nesting allowed in the parsed data - # structures. Enable depth checking with :max_nesting => anInteger. The parse! - # methods defaults to not doing max depth checking: This can be dangerous - # if someone wants to fill up your stack. + # structures. Enable depth checking with :max_nesting => anInteger. The + # parse! methods defaults to not doing max depth checking: This can be + # dangerous if someone wants to fill up your stack. # * *allow_nan*: If set to true, allow NaN, Infinity, and -Infinity in - # defiance of RFC 4627 to be parsed by the Parser. This option defaults + # defiance of RFC 7159 to be parsed by the Parser. This option defaults # to true. # * *create_additions*: If set to false, the Parser doesn't create # additions even if a matching class and create_id was found. This option @@ -175,7 +175,7 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L175 opts = { :max_nesting => false, :allow_nan => true - }.update(opts) + }.merge(opts) Parser.new(source, opts).parse end @@ -296,13 +296,13 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L296 # The global default options for the JSON.load method: # :max_nesting: false # :allow_nan: true - # :quirks_mode: true + # :allow_blank: true attr_accessor :load_default_options end self.load_default_options = { :max_nesting => false, :allow_nan => true, - :quirks_mode => true, + :allow_blank => true, :create_additions => true, } @@ -329,7 +329,7 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L329 elsif source.respond_to?(:read) source = source.read end - if opts[:quirks_mode] && (source.nil? || source.empty?) + if opts[:allow_blank] && (source.nil? || source.empty?) source = 'null' end result = parse(source, opts) @@ -358,13 +358,12 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L358 # The global default options for the JSON.dump method: # :max_nesting: false # :allow_nan: true - # :quirks_mode: true + # :allow_blank: 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 @@ -403,37 +402,9 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L402 raise ArgumentError, "exceed depth limit" end - # Swap consecutive bytes of _string_ in place. - def self.swap!(string) # :nodoc: - 0.upto(string.size / 2) do |i| - break unless string[2 * i + 1] - string[2 * i], string[2 * i + 1] = string[2 * i + 1], string[2 * i] - end - string - end - - # Shortcut for iconv. - if ::String.method_defined?(:encode) - # Encodes string using Ruby's _String.encode_ - def self.iconv(to, from, string) - string.encode(to, from) - end - else - require 'iconv' - # Encodes string using _iconv_ library - def self.iconv(to, from, string) - Iconv.conv(to, from, string) - end - end - - if ::Object.method(:const_defined?).arity == 1 - def self.const_defined_in?(modul, constant) - modul.const_defined?(constant) - end - else - def self.const_defined_in?(modul, constant) - modul.const_defined?(constant, false) - end + # Encodes string using Ruby's _String.encode_ + def self.iconv(to, from, string) + string.encode(to, from) end end Index: ext/json/json.gemspec =================================================================== Binary files ext/json/json.gemspec (revision 55575) and ext/json/json.gemspec (revision 55576) differ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/