Skip to content
Open
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
8 changes: 3 additions & 5 deletions lib/rubygems/util/atomic_file_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def self.open(file_name)
if old_stat
# Set correct permissions on new file
begin
File.chown(old_stat.uid, old_stat.gid, tmp_path)
temp_file.chown(old_stat.uid, old_stat.gid)
# This operation will affect filesystem ACL's
File.chmod(old_stat.mode, tmp_path)
temp_file.chmod(old_stat.mode)
rescue Errno::EPERM, Errno::EACCES
# Changing file ownership failed, moving on.
end
Expand Down Expand Up @@ -99,9 +99,7 @@ def self.open(file_name)
# still be cut mid-character.
def self.byteslice_at_char_boundary(string, max_bytesize)
sliced = string.byteslice(0, max_bytesize)
if string.valid_encoding?
sliced = sliced.byteslice(0, sliced.bytesize - 1) until sliced.valid_encoding?
end
sliced.scrub!("") if string.valid_encoding?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scrub!("") raises Encoding::CompatibilityError for ASCII-incompatible encodings (e.g. UTF-16LE), even when the string is fully valid, because the replacement literal is UTF-8 under frozen_string_literal.

The previous loop handled those encodings gracefully.

sliced
end
private_class_method :byteslice_at_char_boundary
Expand Down