Skip to content

Commit

Permalink
Update json to 1.7.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Feb 13, 2013
1 parent 3294b22 commit a216eb3
Show file tree
Hide file tree
Showing 20 changed files with 444 additions and 127 deletions.
4 changes: 2 additions & 2 deletions lib/ruby/1.9/json.rb
@@ -1,3 +1,5 @@
require 'json/common'

##
# = JavaScript Object Notation (JSON)
#
Expand Down Expand Up @@ -49,8 +51,6 @@
#
# 1.to_json => "1"
#

require 'json/common'
module JSON
require 'json/version'

Expand Down
7 changes: 7 additions & 0 deletions lib/ruby/1.9/json/add/bigdecimal.rb
Expand Up @@ -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
Expand Down
25 changes: 16 additions & 9 deletions lib/ruby/1.9/json/common.rb
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -299,21 +299,28 @@ class << self
attr_accessor :load_default_options
end
self.load_default_options = {
:max_nesting => false,
:allow_nan => true,
:quirks_mode => true,
:max_nesting => false,
:allow_nan => true,
:quirks_mode => true,
:create_additions => true,
}

# Load a ruby data structure from a JSON _source_ and return it. A source can
# either be a string-like object, an IO-like object, or an object responding
# to the read method. If _proc_ was given, it will be called with any nested
# Ruby object as an argument recursively in depth first order. The default
# options for the parser can be changed via the load_default_options method.
# Ruby object as an argument recursively in depth first order. To modify the
# default options pass in the optional _options_ argument as well.
#
# BEWARE: This method is meant to serialise data from trusted user input,
# like from your own database server or clients under your control, it could
# be dangerous to allow untrusted users to pass JSON sources into it. The
# default options for the parser can be changed via the load_default_options
# method.
#
# This method is part of the implementation of the load/dump interface of
# Marshal and YAML.
def load(source, proc = nil)
opts = load_default_options
def load(source, proc = nil, options = {})
opts = load_default_options.merge options
if source.respond_to? :to_str
source = source.to_str
elsif source.respond_to? :to_io
Expand Down
Empty file removed lib/ruby/1.9/json/ext/.keep
Empty file.
Binary file modified lib/ruby/1.9/json/ext/generator.jar
Binary file not shown.
Binary file modified lib/ruby/1.9/json/ext/parser.jar
Binary file not shown.
22 changes: 22 additions & 0 deletions lib/ruby/1.9/json/generic_object.rb
Expand Up @@ -5,12 +5,34 @@ class GenericObject < OpenStruct
class << self
alias [] new

def json_creatable?
@json_creatable
end

attr_writer :json_creatable

def json_create(data)
data = data.dup
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
self.json_creatable = false

def to_hash
table
Expand Down
48 changes: 34 additions & 14 deletions lib/ruby/1.9/json/pure/generator.rb
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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

Expand Down
14 changes: 7 additions & 7 deletions lib/ruby/1.9/json/pure/parser.rb
Expand Up @@ -56,16 +56,16 @@ 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.
# * *symbolize_names*: If set to true, returns symbols for the names
# (keys) in a JSON object. Otherwise strings are returned, which is also
# the default.
# * *create_additions*: If set to false, the Parser doesn't create
# additions even if a matchin class and create_id was found. This option
# defaults to true.
# * *create_additions*: If set to true, the Parser creates
# additions when if a matching class and create_id was found. This
# 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
Expand All @@ -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
Expand All @@ -88,7 +88,7 @@ def initialize(source, opts = {})
if opts.key?(:create_additions)
@create_additions = !!opts[:create_additions]
else
@create_additions = true
@create_additions = false
end
@create_id = @create_additions ? JSON.create_id : nil
@object_class = opts[:object_class] || Hash
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby/1.9/json/version.rb
@@ -1,6 +1,6 @@
module JSON
# JSON version
VERSION = '1.7.5'
VERSION = '1.7.7'
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
Expand Down
2 changes: 1 addition & 1 deletion test/externals/ruby1.9/json/fixtures/fail18.json
@@ -1 +1 @@
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

0 comments on commit a216eb3

Please sign in to comment.