1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

io.c: textmode if newline decorator

* io.c (validate_enc_binmode): newline decorator implies text mode
  now.  [ruby-core:80270] [Bug #13350]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-07-14 10:53:35 +00:00
parent f7ef047f8e
commit 57464618ab
3 changed files with 46 additions and 1 deletions

4
NEWS
View file

@ -32,6 +32,10 @@ with all sufficient information, see the ChangeLog file or Redmine
* Dir.children [Feature #11302]
* Dir.each_child [Feature #11302]
* File
* :newline option to File.open implies text mode now. [Bug #13350]
* Integer
* Integer.sqrt [Feature #13219]

5
io.c
View file

@ -5451,9 +5451,12 @@ validate_enc_binmode(int *fmode_p, int ecflags, rb_encoding *enc, rb_encoding *e
!rb_enc_asciicompat(enc ? enc : rb_default_external_encoding()))
rb_raise(rb_eArgError, "ASCII incompatible encoding needs binmode");
if ((fmode & FMODE_BINMODE) && (ecflags & ECONV_NEWLINE_DECORATOR_MASK)) {
rb_raise(rb_eArgError, "newline decorator with binary mode");
}
if (!(fmode & FMODE_BINMODE) &&
(DEFAULT_TEXTMODE || (ecflags & ECONV_NEWLINE_DECORATOR_MASK))) {
fmode |= DEFAULT_TEXTMODE;
fmode |= FMODE_TEXTMODE;
*fmode_p = fmode;
}
#if !DEFAULT_TEXTMODE

View file

@ -1608,6 +1608,44 @@ EOT
}
end
def test_binmode_decode_universal_newline
with_tmpdir {
generate_file("t.txt", "a\n")
assert_raise(ArgumentError) {
open("t.txt", "rb", newline: :universal) {}
}
}
end
def test_default_mode_decode_universal_newline_gets
with_tmpdir {
generate_file("t.crlf", "a\r\nb\r\nc\r\n")
open("t.crlf", "r", newline: :universal) {|f|
assert_equal("a\n", f.gets)
assert_equal("b\n", f.gets)
assert_equal("c\n", f.gets)
assert_equal(nil, f.gets)
}
generate_file("t.cr", "a\rb\rc\r")
open("t.cr", "r", newline: :universal) {|f|
assert_equal("a\n", f.gets)
assert_equal("b\n", f.gets)
assert_equal("c\n", f.gets)
assert_equal(nil, f.gets)
}
generate_file("t.lf", "a\nb\nc\n")
open("t.lf", "r", newline: :universal) {|f|
assert_equal("a\n", f.gets)
assert_equal("b\n", f.gets)
assert_equal("c\n", f.gets)
assert_equal(nil, f.gets)
}
}
end
def test_read_newline_conversion_with_encoding_conversion
with_tmpdir {
generate_file("t.utf8.crlf", "a\r\nb\r\n")