Permalink
Browse files

Update to JSON 1.7.6. Should fix #512.

  • Loading branch information...
1 parent 120d34e commit bf5365f411eed19681cf5a2e916d4a65123c4bd2 @BanzaiMan BanzaiMan committed Jan 25, 2013
@@ -4,17 +4,24 @@
defined?(::BigDecimal) or require 'bigdecimal'
class BigDecimal
+ # Import a JSON Marshalled object.
+ #
+ # method used for JSON marshalling support.
def self.json_create(object)
BigDecimal._load object['b']
end
+ # Marshal the object to JSON.
+ #
+ # method used for JSON marshalling support.
def as_json(*)
{
JSON.create_id => self.class.name,
'b' => _dump,
}
end
+ # return the JSON value
def to_json(*)
as_json.to_json
end
@@ -139,7 +139,7 @@ class MissingUnicodeSupport < JSONError; end
# keys:
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
# structures. Disable depth checking with :max_nesting => false. It defaults
- # to 19.
+ # 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
# to false.
@@ -199,7 +199,7 @@ def parse!(source, opts = {})
# encountered. This options defaults to false.
# * *max_nesting*: The maximum depth of nesting allowed in the data
# structures from which JSON is to be generated. Disable depth checking
- # with :max_nesting => false, it defaults to 19.
+ # with :max_nesting => false, it defaults to 100.
#
# See also the fast_generate for the fastest creation method with the least
# amount of sanity checks, and the pretty_generate method for some
Binary file not shown.
Binary file not shown.
@@ -10,6 +10,21 @@ def json_create(data)
data.delete JSON.create_id
self[data]
end
+
+ def from_hash(object)
+ case
+ when object.respond_to?(:to_hash)
+ result = new
+ object.to_hash.each do |key, value|
+ result[key] = from_hash(value)
+ end
+ result
+ when object.respond_to?(:to_ary)
+ object.to_ary.map { |a| from_hash(a) }
+ else
+ object
+ end
+ end
end
def to_hash
@@ -220,17 +220,22 @@ def quirks_mode?
# Configure this State instance with the Hash _opts_, and return
# itself.
def configure(opts)
- @indent = opts[:indent] if opts.key?(:indent)
- @space = opts[:space] if opts.key?(:space)
- @space_before = opts[:space_before] if opts.key?(:space_before)
- @object_nl = opts[:object_nl] if opts.key?(:object_nl)
- @array_nl = opts[:array_nl] if opts.key?(:array_nl)
- @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)
- if !opts.key?(:max_nesting) # defaults to 19
- @max_nesting = 19
+ for key, value in opts
+ instance_variable_set "@#{key}", value
+ end
+ @indent = opts[:indent] if opts.key?(:indent)
+ @space = opts[:space] if opts.key?(:space)
+ @space_before = opts[:space_before] if opts.key?(:space_before)
+ @object_nl = opts[:object_nl] if opts.key?(:object_nl)
+ @array_nl = opts[:array_nl] if opts.key?(:array_nl)
+ @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
+ @max_nesting = 100
elsif opts[:max_nesting]
@max_nesting = opts[:max_nesting]
else
@@ -244,12 +249,15 @@ def configure(opts)
# passed to the configure method.
def to_h
result = {}
- for iv in %w[indent space space_before object_nl array_nl allow_nan max_nesting ascii_only quirks_mode buffer_initial_length depth]
- result[iv.intern] = instance_variable_get("@#{iv}")
+ for iv in instance_variables
+ iv = iv.to_s[1..-1]
+ result[iv.to_sym] = self[iv]
end
result
end
+ alias to_hash to_h
+
# Generates a valid JSON document from object +obj+ and returns the
# result. If no valid JSON document can be created this method raises a
# GeneratorError exception.
@@ -267,7 +275,19 @@ def generate(obj)
# Return the value returned by method +name+.
def [](name)
- __send__ name
+ if respond_to?(name)
+ __send__(name)
+ else
+ instance_variable_get("@#{name}")
+ end
+ end
+
+ def []=(name, value)
+ if respond_to?(name_writer = "#{name}=")
+ __send__ name_writer, value
+ else
+ instance_variable_set "@#{name}", value
+ end
end
end
@@ -56,7 +56,7 @@ class Parser < StringScanner
# keys:
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
# structures. Disable depth checking with :max_nesting => false|nil|0,
- # it defaults to 19.
+ # 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
# to false.
@@ -76,8 +76,8 @@ def initialize(source, opts = {})
source = convert_encoding source
end
super source
- if !opts.key?(:max_nesting) # defaults to 19
- @max_nesting = 19
+ if !opts.key?(:max_nesting) # defaults to 100
+ @max_nesting = 100
elsif opts[:max_nesting]
@max_nesting = opts[:max_nesting]
else
@@ -1,6 +1,6 @@
module JSON
# JSON version
- VERSION = '1.7.5'
+ VERSION = '1.7.6'
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:

0 comments on commit bf5365f

Please sign in to comment.