mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Set external encoding correctly for File.open('f', FILE::BINARY) on Windows
Previously, the external encoding was only set correctly for File::BINARY if keyword arguments were provided. This copies the logic for the keyword arguments case to the no keyword arguments case. Possibly it should be refactored into a separate function. Fixes [Bug #16737]
This commit is contained in:
parent
3486a460ea
commit
e1e4ea8fa9
Notes:
git
2020-03-28 03:31:54 +09:00
2 changed files with 24 additions and 0 deletions
12
io.c
12
io.c
|
@ -5955,6 +5955,18 @@ rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash,
|
|||
#endif
|
||||
SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags);
|
||||
ecopts = Qnil;
|
||||
if (fmode & FMODE_BINMODE) {
|
||||
#ifdef O_BINARY
|
||||
oflags |= O_BINARY;
|
||||
#endif
|
||||
if (!has_enc)
|
||||
rb_io_ext_int_to_encs(rb_ascii8bit_encoding(), NULL, &enc, &enc2, fmode);
|
||||
}
|
||||
#if DEFAULT_TEXTMODE
|
||||
else if (NIL_P(vmode)) {
|
||||
fmode |= DEFAULT_TEXTMODE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
VALUE v;
|
||||
|
|
|
@ -3630,15 +3630,27 @@ __END__
|
|||
end
|
||||
|
||||
def test_open_flag_binary
|
||||
binary_enc = Encoding.find("BINARY")
|
||||
make_tempfile do |t|
|
||||
open(t.path, File::RDONLY, flags: File::BINARY) do |f|
|
||||
assert_equal true, f.binmode?
|
||||
assert_equal binary_enc, f.external_encoding
|
||||
end
|
||||
open(t.path, 'r', flags: File::BINARY) do |f|
|
||||
assert_equal true, f.binmode?
|
||||
assert_equal binary_enc, f.external_encoding
|
||||
end
|
||||
open(t.path, mode: 'r', flags: File::BINARY) do |f|
|
||||
assert_equal true, f.binmode?
|
||||
assert_equal binary_enc, f.external_encoding
|
||||
end
|
||||
open(t.path, File::RDONLY|File::BINARY) do |f|
|
||||
assert_equal true, f.binmode?
|
||||
assert_equal binary_enc, f.external_encoding
|
||||
end
|
||||
open(t.path, File::RDONLY|File::BINARY, autoclose: true) do |f|
|
||||
assert_equal true, f.binmode?
|
||||
assert_equal binary_enc, f.external_encoding
|
||||
end
|
||||
end
|
||||
end if File::BINARY != 0
|
||||
|
|
Loading…
Reference in a new issue