diff options
| author | Florian Frank <flori@ping.de> | 2011-01-01 05:18:52 +0100 | 
|---|---|---|
| committer | Florian Frank <flori@ping.de> | 2011-01-02 21:13:45 +0100 | 
| commit | 9b900f591de3b01325366909ebae9dc5696c1f5c (patch) | |
| tree | 2a576575b23b18f098f8e000c98142ebc3223610 | |
| parent | 52cab32644a0f77ffa7653232f79724b33f19050 (diff) | |
| download | json-9b900f591de3b01325366909ebae9dc5696c1f5c.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  | 
