summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ext/json/lib/json/pure/generator.rb4
2 files changed, 7 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 03a83498342..3392441791c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Oct 7 16:43:51 2008 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * ext/json/lib/json/pure/generator.rb (utf8_to_json):
+ force_encoding before gsub.
+
Tue Oct 7 16:35:41 2008 NARUSE, Yui <naruse@ruby-lang.org>
* 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 b44e42ac41e..abc24bf72d7 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] |