Skip to content

fix(read): preserve line endings in numbered output - #4828

Closed
GeorgiaPreda wants to merge 1 commit into
rtk-ai:developfrom
GeorgiaPreda:fix/read-preserve-numbered-line-endings
Closed

GeorgiaPreda wants to merge 1 commit into
rtk-ai:developfrom
GeorgiaPreda:fix/read-preserve-numbered-line-endings

Conversation

@GeorgiaPreda

Copy link
Copy Markdown

Summary

Fixes #4816.

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.

@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

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.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4816


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
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.

@KuSh

KuSh commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

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.

@KuSh KuSh closed this Nov 16, 2026
@KuSh KuSh added the duplicate This issue or pull request already exists label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix cli duplicate This issue or pull request already exists needs-cla read tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk read -n (target of the cat -n rewrite) drops carriage returns and adds a final newline

3 participants