1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
naruse 2008-10-07 07:50:43 +00:00
parent 6d58b1e54f
commit 84f677d2f3
2 changed files with 7 additions and 2 deletions

View file

@ -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):

View file

@ -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] |