Bug #12436
closednewline argument of File.open seems not respected on Windows
Description
File.open("abc", "wt", newline: :lf) { |f|
f.write "a\n"
f.puts "b"
}
will create a file with CRLF newlines, ignoring the newline conversion argument.
It should write only LF instead, like on other platforms when the newline conversion is specified.
Updated by jeremyevans0 (Jeremy Evans) over 3 years ago
This issue dates to the introduction of the newline code in c26ab1ef1c1129198695edf2212774a084147228. It looks like newline: :lf
was originally planned, but never implemented. However, the state it was left in resulted in newline: :lf
not raising an ArgumentError (as all other invalid :newline option values do), but just being ignored. Since I think the behavior that would be desired for newline: :lf
is already present in newline: :universal
, it's simple to newline: :lf
an alias for that. I submitted a pull request that does that: https://github.com/ruby/ruby/pull/4590
Updated by mame (Yusuke Endoh) about 3 years ago
- Assignee set to usa (Usaku NAKAMURA)
Updated by mame (Yusuke Endoh) about 3 years ago
- Status changed from Open to Assigned
- Assignee changed from usa (Usaku NAKAMURA) to nobu (Nobuyoshi Nakada)
@matz (Yukihiro Matsumoto) accepted this and asked @nobu (Nobuyoshi Nakada) to review the PR.
Updated by jeremyevans (Jeremy Evans) over 2 years ago
- Status changed from Assigned to Closed
Applied in changeset git|6f3857f6a7b3cd6bd7e62e4efdbb1b841544e053.
Support Encoding::Converter newline: :lf and :lf_newline options
Previously, newline: :lf was accepted but ignored. Where it
should have been used was commented out code that didn't work,
but unlike all other invalid values, using newline: :lf did
not raise an error.
This adds support for newline: :lf and :lf_newline, for consistency
with newline: :cr and :cr_newline. This is basically the same as
universal_newline, except that it only affects writing and not
reading due to RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK.
Add tests for the File.open :newline option while here.
Fixes [Bug #12436]