You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(read): preserve line endings in numbered output - #4828
rtk read -n drops carriage returns and appends a newline to an unterminated final line. Split inclusively on LF and retain each original segment when adding line numbers, preserving CRLF, LF, lone CR, and missing final newlines.
Add CLI regression tests for files and stdin, including mixed endings, blank lines, empty input, Unicode, and head/tail windows. The existing numbered gutter is unchanged.
Test plan
New regression tests fail before the fix and pass after it.
cargo fmt --all --check
cargo clippy --all-targets
cargo test (with PATH excluding a broken preinstalled pip launcher whose interpreter is missing)
cargo test --test read_window_bytes_test: 7 passed
Manual comparisons against cat -n for eight inputs, comparing content and line terminators after removing the respective gutters.
Fixes a bug where rtk read -n stripped carriage returns and appended a trailing newline to unterminated final lines. The fix switches from .lines() to .split_inclusive('\n') in format_with_line_numbers so original line terminators (CRLF, LF, lone CR, missing final newline) are preserved when numbering output. Adds CLI regression tests covering files, stdin, mixed endings, blank lines, empty input, Unicode, and head/tail windows.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You have signed the CLA already but the status is still pending? Let us recheck it.
Closing as a duplicate of #4872, which fixes the same rtk read -n line-ending bug (#4816) with the same split and has a signed CLA. Your CLI tests over files, stdin and head/tail windows go further than its unit test, so a review comment on #4872 proposing them would be welcome, or reply here if your scope differs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Summary
Fixes #4816.
rtk read -ndrops carriage returns and appends a newline to an unterminated final line. Split inclusively on LF and retain each original segment when adding line numbers, preserving CRLF, LF, lone CR, and missing final newlines.Add CLI regression tests for files and stdin, including mixed endings, blank lines, empty input, Unicode, and head/tail windows. The existing numbered gutter is unchanged.
Test plan
cargo fmt --all --checkcargo clippy --all-targetscargo test(with PATH excluding a broken preinstalled pip launcher whose interpreter is missing)cargo test --test read_window_bytes_test: 7 passedcat -nfor eight inputs, comparing content and line terminators after removing the respective gutters.