diff options
author | Florian Frank <flori@ping.de> | 2011-12-21 11:05:46 +0100 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2011-12-21 11:05:46 +0100 |
commit | 60ef7adb347b473cbcce9aacacb2943ae5fb4d4c (patch) | |
tree | ba73bea0660d74b2a9a787c5e0acd1a06739e1b6 /lib/json/pure/parser.rb | |
parent | 0dacb54bcdf3c40cc38dae26f04b780024460b45 (diff) | |
parent | 59ecfad89281873fe72234b62545294b5fa7ba95 (diff) | |
download | json-MagLev-master.tar.gz |
Merge branch 'master' of https://github.com/MagLev/json into MagLev-masterMagLev-master
Diffstat (limited to 'lib/json/pure/parser.rb')
-rw-r--r-- | lib/json/pure/parser.rb | 9 |
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 |