Project

General

Profile

Actions

Bug #12436

open

newline argument of File.open seems not respected on Windows

Added by Eregon (Benoit Daloze) almost 6 years ago. Updated 7 months ago.

Status:
Assigned
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]
[ruby-core:75767]
Tags:

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) 11 months 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) 7 months ago

  • Assignee set to usa (Usaku NAKAMURA)

Updated by mame (Yusuke Endoh) 7 months ago

  • Assignee changed from usa (Usaku NAKAMURA) to nobu (Nobuyoshi Nakada)
  • Status changed from Open to Assigned

@matz (Yukihiro Matsumoto) accepted this and asked @nobu (Nobuyoshi Nakada) to review the PR.

Actions

Also available in: Atom PDF