mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[rubygems/rubygems] Pass :bimode
explicitly to File.open
The `File::BINARY` flag is apparently ignored due to a ruby bug, and thus writing can cause encoding issues. https://github.com/rubygems/rubygems/commit/db4efbebf2
This commit is contained in:
parent
c2dbdf3067
commit
9f87c0cc6d
2 changed files with 16 additions and 1 deletions
|
@ -800,7 +800,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
|
|||
##
|
||||
# Safely write a file in binary mode on all platforms.
|
||||
def self.write_binary(path, data)
|
||||
File.open(path, File::RDWR | File::CREAT | File::BINARY | File::LOCK_EX) do |io|
|
||||
File.open(path, File::RDWR | File::CREAT | File::LOCK_EX, binmode: true) do |io|
|
||||
io.write data
|
||||
end
|
||||
rescue *WRITE_BINARY_ERRORS
|
||||
|
|
|
@ -173,6 +173,21 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
|
|||
assert_equal 'hello', File.read(path)
|
||||
end
|
||||
|
||||
def test_cache_update_path_with_utf8_internal_encoding
|
||||
with_internal_encoding('UTF-8') do
|
||||
uri = URI 'http://example/file'
|
||||
path = File.join @tempdir, 'file'
|
||||
data = String.new("\xC8").force_encoding(Encoding::BINARY)
|
||||
|
||||
fetcher = util_fuck_with_fetcher data
|
||||
|
||||
written_data = fetcher.cache_update_path uri, path
|
||||
|
||||
assert_equal data, written_data
|
||||
assert_equal data, File.binread(path)
|
||||
end
|
||||
end
|
||||
|
||||
def test_cache_update_path_no_update
|
||||
uri = URI 'http://example/file'
|
||||
path = File.join @tempdir, 'file'
|
||||
|
|
Loading…
Reference in a new issue