Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File.open w/ File::RDWR should write \r\n but gets should read as \n after rewind on windows #3742

Open
enebo opened this issue Mar 17, 2016 · 6 comments
Labels

Comments

@enebo
Copy link
Member

enebo commented Mar 17, 2016

Environment

Note: duplicated issue from #3738. This is broken differently than 1.7's version of this bug so I made a new issue to track it on 9k.

Broken on 9.0.5.0.

Expected Behavior

For the following script:

file = "temptemp"

File.open(file, "w") {}
File.open(file, File::RDWR) do |f|
  f.puts("writing")  # writes "writing\r\n"
  f.flush            # force to disk
  gets               # do not continue until you can verify it was written right
  f.rewind           # backup
  p f.gets           # read it but it should be "writing\n"
end
File.unlink(file)

The comments dictate how it should behave.

Actual Behavior

On JRuby 9.0.5.0 it wil write "writing\n" instead of "writing\r\n" but it will read "writing\n".

@enebo enebo added the windows label Mar 17, 2016
@enebo enebo added this to the JRuby 9.1.0.0 milestone Mar 17, 2016
@enebo enebo modified the milestones: JRuby 9.1.1.0, JRuby 9.1.0.0 Apr 20, 2016
@enebo
Copy link
Member Author

enebo commented Apr 20, 2016

Bumping discovered windows issues from 1.7 windows work to 9.1.1.0 because we have not CI-greened 9k on appveyor yet. Next release we will have greenness.

@headius headius modified the milestones: JRuby 9.1.1.0, JRuby 9.1.2.0 May 11, 2016
@enebo enebo modified the milestones: JRuby 9.1.2.0, JRuby 9.1.3.0 May 23, 2016
@headius
Copy link
Member

headius commented Aug 16, 2016

Next release, and the one after it, still don't have greenness on Appveyor...and this is an internal report, so I guess we bump it again.

@ahorek
Copy link
Contributor

ahorek commented Jul 5, 2018

file = "temptemp"
File.open(file, "wb") { |f| f.puts("\r\n") }
File.open(file, "r") { |f| p f.gets }
File.unlink(file)

on windows it should print "\n" but it prints "\r\n"

@headius headius removed this from the JRuby 9.2.1.0 milestone Oct 26, 2018
@headius headius added this to the JRuby 9.3.0.0 milestone Oct 26, 2018
@headius
Copy link
Member

headius commented Jul 1, 2021

Based on @ahorek example this is still broken on Windows. It writes crlf to the file and reads it back in as crlf. Seems like binary mode is not working properly for this case but I am confirming CRuby behavior now.

@headius
Copy link
Member

headius commented Jul 1, 2021

CRuby also writes CRLF to the file. The read is where it normalizes back to just LF, due to the mode not being b.

On JRuby:

  • mode wb with a write of CRLF writes CRLF
  • mode w with a write of CRLF writes CRLF
  • mode w with a write of LF writes CRLF
  • more rb with a file containing CRLF reads CRLF
  • mode r with a file containing CRLF reads CRLF

On CRuby:

  • mode wb with a write of CRLF writes CRLF
  • mode w with a write of CRLF writes CRLF
  • mode w with a write of LF writes CRLF
  • mode r with a file containing CRLF reads LF
  • mode rb with a file containing CRLF reads CRLF

Only the non-binary read mode seems to be in error here.

@headius
Copy link
Member

headius commented Jul 1, 2021

It appears at a glance that we are setting up the right newline conversions in the IO transcoding pipeline, so this one will take more stepping to see why it is not normalizing CRLF to LF on a non-binary read.

Not a critical item so punting to 9.3.1.

@headius headius modified the milestones: JRuby 9.3.0.0, JRuby 9.3.1.0 Jul 1, 2021
@headius headius modified the milestones: JRuby 9.3.1.0, JRuby 9.3.2.0 Oct 13, 2021
@enebo enebo removed this from the JRuby 9.3.2.0 milestone Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants