summaryrefslogtreecommitdiff
path: root/ext/json
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 /ext/json
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
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/lib/json/pure/generator.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/ext/json/lib/json/pure/generator.rb b/ext/json/lib/json/pure/generator.rb
index b44e42a..abc24bf 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] |