Skip to content

Commit c40a330

Browse files
committed
Use String#b
1 parent d48f7ff commit c40a330

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lib/json/pure/generator.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ module JSON
5050
# Convert a UTF8 encoded Ruby string _string_ to a JSON string, encoded with
5151
# UTF16 big endian characters as \u????, and return it.
5252
def utf8_to_json(string, script_safe = false) # :nodoc:
53-
string = string.dup
54-
string.force_encoding(::Encoding::ASCII_8BIT)
53+
string = string.b
5554
if script_safe
5655
string.gsub!(SCRIPT_SAFE_ESCAPE_PATTERN) { SCRIPT_SAFE_MAP[$&] || $& }
5756
else
@@ -62,8 +61,7 @@ def utf8_to_json(string, script_safe = false) # :nodoc:
6261
end
6362

6463
def utf8_to_json_ascii(string, script_safe = false) # :nodoc:
65-
string = string.dup
66-
string.force_encoding(::Encoding::ASCII_8BIT)
64+
string = string.b
6765
map = script_safe ? SCRIPT_SAFE_MAP : MAP
6866
string.gsub!(/[\/"\\\x0-\x1f]/n) { map[$&] || $& }
6967
string.gsub!(/(

0 commit comments

Comments
 (0)