-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
cat -n doesn't handle CRLF newline delimiters correctly #6248
Comments
I'm trying to fix this issue. And I find out that it is caused by fn write_new_line<W: Write>(
writer: &mut W,
options: &OutputOptions,
state: &mut OutputState,
is_interactive: bool,
) -> CatResult<()> {
if state.skipped_carriage_return && options.show_ends {
writer.write_all(b"^M")?;
state.skipped_carriage_return = false;
}
if !state.at_line_start || !options.squeeze_blank || !state.one_blank_kept {
state.one_blank_kept = true;
if state.at_line_start && options.number == NumberingMode::All {
write!(writer, "{0:6}\t", state.line_number)?;
state.line_number += 1;
}
writer.write_all(options.end_of_line().as_bytes())?;
if is_interactive {
writer.flush()?;
}
}
Ok(())
} I think there's two problems in this function:
I think these problems can be fixed by modiying the branch statement in function if state.skipped_carriage_return {
if options.show_ends {
writer.write_all(b"^M")?;
} else {
writer.write_all(b"\r")?;
}
state.skipped_carriage_return = false;
write_end_of_line(writer, options.end_of_line().as_bytes(), is_interactive)?;
return Ok(());
} I'll be glad to submit a PR if you agree to my proposal. Besides, I think tests for this kind of case should be added. But I have no idea where should I add the new test. I'm new in here so please give some guidance, thanks. |
Sure, don't hesitate to submit the PR |
You can add the test to |
This is with the latest version from github, built locally via
cargo build --release --features windows
Weirdly, looking at the output via xxd, the CRLF sequence is switched to LFCR...
The text was updated successfully, but these errors were encountered: