Skip to content

Commit

Permalink
Use String#b
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Oct 24, 2024
1 parent d48f7ff commit c40a330
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/json/pure/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ 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, script_safe = false) # :nodoc:
string = string.dup
string.force_encoding(::Encoding::ASCII_8BIT)
string = string.b
if script_safe
string.gsub!(SCRIPT_SAFE_ESCAPE_PATTERN) { SCRIPT_SAFE_MAP[$&] || $& }
else
Expand All @@ -62,8 +61,7 @@ def utf8_to_json(string, script_safe = false) # :nodoc:
end

def utf8_to_json_ascii(string, script_safe = false) # :nodoc:
string = string.dup
string.force_encoding(::Encoding::ASCII_8BIT)
string = string.b
map = script_safe ? SCRIPT_SAFE_MAP : MAP
string.gsub!(/[\/"\\\x0-\x1f]/n) { map[$&] || $& }
string.gsub!(/(
Expand Down

0 comments on commit c40a330

Please sign in to comment.