lib/json/pure/parser.rb in json_pure-1.1.3 vs lib/json/pure/parser.rb in json_pure-1.1.4

- old
+ new

@@ -120,22 +120,26 @@ }) def parse_string if scan(STRING) return '' if self[1].empty? - self[1].gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c| + string = self[1].gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c| if u = UNESCAPE_MAP[$&[1]] u else # \uXXXX bytes = '' i = 0 - while c[6 * i] == ?\\ && c[6 * i + 1] == ?u + 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) i += 1 end JSON::UTF16toUTF8.iconv(bytes) end end + if string.respond_to?(:force_encoding) + string.force_encoding(Encoding::UTF_8) + end + string else UNPARSED end rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}"