Fix CRLF -> LF conversion on read for rb_io_fdopen & rb_file_open #9380
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When opening a file with
File.open
, and then setting the encoding withIO#set_encoding
, it still correctly performs CRLF -> LF conversion on Windows when reading files with a CRLF line ending in them (in text mode).However, the file is opened instead with either the
rb_io_fdopen
orrb_file_open
APIs from C, the CRLF conversion is NOT set up correctly; it works if the encoding is not specified, but ifIO#set_encoding
is called, the conversion stops happening. This seems to be because the encflags never get ECONV_DEFAULT_NEWLINE_DECORATOR set in these codepaths.Concretely, this means that the conversion doesn't happen in the following circumstances:
This commit fixes the problem by copy-pasting the relevant snippet which sets this up in
rb_io_extract_modeenc
(for the File.open path) into the relevant codepaths forrb_io_fdopen
andrb_file_open
.[Bug #20101]