summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-07 07:50:43 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-07 07:50:43 +0000
commit84f677d2f38f596f71d6aea54ba2da68f4f60855 (patch)
tree6eb0d1d12e815dca5bc7c522e2544363c91b1807
parent6d58b1e54fa9b801382e18f49aff805bba7f7c85 (diff)
* ext/json/lib/json/pure/generator.rb (utf8_to_json):
force_encoding before gsub. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-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] |