From 9b900f591de3b01325366909ebae9dc5696c1f5c Mon Sep 17 00:00:00 2001 From: Florian Frank Date: Sat, 1 Jan 2011 05:18:52 +0100 Subject: make sure bytes is a 8-bit string on all rubies --- lib/json/pure/parser.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/json/pure/parser.rb') 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 -- cgit v1.2.1