ruby-changes:47221
From: nobu <ko1@a...>
Date: Fri, 14 Jul 2017 19:53:50 +0900 (JST)
Subject: [ruby-changes:47221] nobu:r59336 (trunk): io.c: textmode if newline decorator
nobu 2017-07-14 19:53:35 +0900 (Fri, 14 Jul 2017) New Revision: 59336 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59336 Log: io.c: textmode if newline decorator * io.c (validate_enc_binmode): newline decorator implies text mode now. [ruby-core:80270] [Bug #13350] Modified files: trunk/NEWS trunk/io.c trunk/test/ruby/test_io_m17n.rb Index: io.c =================================================================== --- io.c (revision 59335) +++ io.c (revision 59336) @@ -5451,9 +5451,12 @@ validate_enc_binmode(int *fmode_p, int e https://github.com/ruby/ruby/blob/trunk/io.c#L5451 !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 Index: NEWS =================================================================== --- NEWS (revision 59335) +++ NEWS (revision 59336) @@ -32,6 +32,10 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L32 * 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] Index: test/ruby/test_io_m17n.rb =================================================================== --- test/ruby/test_io_m17n.rb (revision 59335) +++ test/ruby/test_io_m17n.rb (revision 59336) @@ -1608,6 +1608,44 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_m17n.rb#L1608 } 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") -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/