diff options
author | Florian Frank <flori@ping.de> | 2011-01-01 05:18:52 +0100 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2011-01-01 20:06:22 +0100 |
commit | f7ba076838b3b565b28f0daae572f0866fb6fe84 (patch) | |
tree | 2a576575b23b18f098f8e000c98142ebc3223610 | |
parent | 88a8940f0bcc0658b99d14e5535ad3011b2fe82b (diff) | |
download | json-f7ba076838b3b565b28f0daae572f0866fb6fe84.tar.gz |
make sure bytes is a 8-bit string on all rubies
-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 c166749..82a21e8 100644 --- a/lib/json/pure/parser.rb +++ b/lib/json/pure/parser.rb @@ -165,6 +165,11 @@ module JSON ?u => nil, }) + EMPTY_8BIT_STRING = '' + if ::String.method_defined?(:encode) + EMPTY_8BIT_STRING.force_encoding Encoding::ASCII_8BIT + end + def parse_string if scan(STRING) return '' if self[1].empty? @@ -172,7 +177,7 @@ module JSON if u = UNESCAPE_MAP[$&[1]] u else # \uXXXX - bytes = '' + bytes = EMPTY_8BIT_STRING.dup i = 0 while c[6 * i] == ?\\ && c[6 * i + 1] == ?u bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16) @@ -189,7 +194,7 @@ module JSON UNPARSED end rescue => e - raise ParserError, "Caught #{e.class}: #{e}" + raise ParserError, "Caught #{e.class} at '#{peek(20)}': #{e}" end def parse_value |