diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-07 17:15:30 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-07 17:15:30 +0000 |
commit | 322003ef8f2c36d24f1d009eda5408102f5658ae (patch) | |
tree | a7a8a5c2ed9fc9c94759cb02fc9a789d9885387e /lib/json/pure/parser.rb | |
parent | acbffce267b63bb06281f3ebe6a8bb0d897d4566 (diff) | |
download | ruby-322003ef8f2c36d24f1d009eda5408102f5658ae.tar.gz |
* lib/json.rb, lib/json/, ext/json/:
import JSON 1.1.1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/json/pure/parser.rb')
-rw-r--r-- | lib/json/pure/parser.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb index 6118fe489e..4d63464320 100644 --- a/lib/json/pure/parser.rb +++ b/lib/json/pure/parser.rb @@ -19,6 +19,9 @@ module JSON (?i:e[+-]?\d+) ) )/x + NAN = /NaN/ + INFINITY = /Infinity/ + MINUS_INFINITY = /-Infinity/ OBJECT_OPEN = /\{/ OBJECT_CLOSE = /\}/ ARRAY_OPEN = /\[/ @@ -50,7 +53,11 @@ module JSON # It will be configured by the _opts_ hash. _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. + # structures. Disable depth checking with :max_nesting => false|nil|0, + # it defaults to 19. + # * *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. def initialize(source, opts = {}) super if !opts.key?(:max_nesting) # defaults to 19 @@ -60,6 +67,7 @@ module JSON else @max_nesting = 0 end + @allow_nan = !!opts[:allow_nan] @create_id = JSON.create_id end @@ -153,6 +161,12 @@ module JSON obj = parse_object @current_nesting -= 1 obj + when @allow_nan && scan(NAN) + NaN + when @allow_nan && scan(INFINITY) + Infinity + when @allow_nan && scan(MINUS_INFINITY) + MinusInfinity else UNPARSED end |