summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2011-11-03 13:04:02 +0100
committerFlorian Frank <flori@ping.de>2011-11-03 13:04:02 +0100
commit6bd324502763b85914e98bcd9eb97615306146a4 (patch)
treedb2a965cfe53f47c488e65096269a07a16144b5a /lib
parent5dcfa3711a14a6a027ce6b2b62d9117fb78da1b7 (diff)
downloadjson-6bd324502763b85914e98bcd9eb97615306146a4.tar.gz
always raise type error when parsing nil
Diffstat (limited to 'lib')
-rw-r--r--lib/json/pure/parser.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb
index e24aac1..84eb67f 100644
--- a/lib/json/pure/parser.rb
+++ b/lib/json/pure/parser.rb
@@ -73,7 +73,7 @@ module JSON
def initialize(source, opts = {})
opts ||= {}
unless @quirks_mode = opts[:quirks_mode]
- source = determine_encoding source
+ source = convert_encoding source
end
super source
if !opts.key?(:max_nesting) # defaults to 19
@@ -145,7 +145,12 @@ module JSON
private
- def determine_encoding(source)
+ def convert_encoding(source)
+ if source.respond_to?(:to_str)
+ source = source.to_str
+ else
+ raise TypeError, "#{source.inspect} is not like a string"
+ end
if defined?(::Encoding)
if source.encoding == ::Encoding::ASCII_8BIT
b = source[0, 4].bytes.to_a