diff --git a/ChangeLog b/ChangeLog index 03a8349834..3392441791 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Oct 7 16:43:51 2008 NARUSE, Yui + + * ext/json/lib/json/pure/generator.rb (utf8_to_json): + force_encoding before gsub. + Tue Oct 7 16:35:41 2008 NARUSE, Yui * ext/json/lib/json/pure/generator.rb (utf8_to_json): diff --git a/ext/json/lib/json/pure/generator.rb b/ext/json/lib/json/pure/generator.rb index b44e42ac41..abc24bf72d 100644 --- a/ext/json/lib/json/pure/generator.rb +++ b/ext/json/lib/json/pure/generator.rb @@ -40,8 +40,8 @@ module JSON # Convert a UTF8 encoded Ruby string _string_ to a JSON string, encoded with # UTF16 big endian characters as \u????, and return it. def utf8_to_json(string) # :nodoc: - string = string.gsub(/["\\\/\x0-\x1f]/) { MAP[$&] } - string.force_encoding(Encoding::ASCII_8BIT) + string = string.dup.force_encoding(Encoding::ASCII_8BIT) + string.gsub!(/["\\\/\x0-\x1f]/) { MAP[$&] } string.gsub!(/( (?: [\xc2-\xdf][\x80-\xbf] |