Skip to content

Keep UTF-16 line splitting aligned to code units - #4110

Merged
keith-hall merged 2 commits into
sharkdp:masterfrom
Marve10s:fix/utf16-line-alignment
Nov 4, 2026
Merged

keith-hall merged 2 commits into
sharkdp:masterfrom
Marve10s:fix/utf16-line-alignment

Conversation

@Marve10s

@Marve10s Marve10s commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Valid UTF-16 input can be split inside a code unit when two bytes spanning adjacent characters resemble a newline. This corrupts the decoded text and shifts source line numbers, so line ranges can select the wrong content.

Require the newline pair to end at an even accumulated byte count. This preserves code-unit alignment for both byte orders while retaining the existing initialization, EOF and error handling. Add reader and CLI regressions for intact text, subsequent lines and range selection.

Verification

On v0.26.1 and current master, BOM-marked UTF-16LE input અ─\nnext\n with numbered formatted output produces:

   1 અ�
   2 ਥ�
   3 next

The branch produces:

   1 અ─
   2 next

--line-range=2 now selects next. A later-line UTF-16BE case also fails before and passes after. Both new Rust regression tests compiled and failed against the original production code, then passed with the correction.

cargo fmt -- --check, locked all-target/all-feature check and Clippy with -D warnings, and cargo test --locked pass. The full suite reports 467 passed and five ignored.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T16:37:03.749805Z 94e9ae4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@keith-hall
keith-hall merged commit 73676df into sharkdp:master Nov 4, 2026
24 checks passed
cindykrafft pushed a commit to cindykrafft/bat that referenced this pull request Nov 4, 2026
Resolve the CHANGELOG conflict: keep the sharkdp#4111 and sharkdp#4110 entries and
drop the stale UTF-16BE '#XXXX' duplicate (the entry is listed as sharkdp#4076).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants