Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid modifying frozen strings #649

Merged
merged 1 commit into from
Mar 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/httparty/text_encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ def encoded_text
def encode_utf_16
if text.bytesize >= 2
if text.getbyte(0) == 0xFF && text.getbyte(1) == 0xFE
return text.force_encoding("UTF-16LE")
return text.dup.force_encoding("UTF-16LE")
elsif text.getbyte(0) == 0xFE && text.getbyte(1) == 0xFF
return text.force_encoding("UTF-16BE")
return text.dup.force_encoding("UTF-16BE")
end
end

if assume_utf16_is_big_endian # option
text.force_encoding("UTF-16BE")
text.dup.force_encoding("UTF-16BE")
else
text.force_encoding("UTF-16LE")
text.dup.force_encoding("UTF-16LE")
end
end

def encode_with_ruby_encoding
# NOTE: This will raise an argument error if the
# charset does not exist
encoding = Encoding.find(charset)
text.force_encoding(encoding.to_s)
text.dup.force_encoding(encoding.to_s)
rescue ArgumentError
text
end
Expand Down