Skip to content

fix: skip empty UTF-16 lines in nonblank numbering - #4118

Merged
keith-hall merged 2 commits into
sharkdp:masterfrom
pcbeingused33:fix/utf16-nonblank-c1626
Nov 7, 2026
Merged

keith-hall merged 2 commits into
sharkdp:masterfrom
pcbeingused33:fix/utf16-nonblank-c1626

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

Fix nonblank line numbering for UTF-16 input.

The controller checks raw CR/LF bytes when deciding whether to advance the nonblank line counter. UTF-16 line terminators contain NUL bytes, so empty lines incorrectly advance the counter even though the printer hides their numbers. As a result, alpha\n\nbeta\n is numbered 1, 3 instead of 1, 2.

Decode UTF-16 before checking for empty lines, using the same BOM removal and CR/LF predicate as the printer. Keep the byte predicate for other encodings. Add integration coverage for LE/BE BOMs, LF/CRLF, leading/trailing blank lines, and spaces/tabs that must remain numbered, plus a changelog entry.

Validation: the regression failed on the original controller (5 passed, 1 failed, showing 3 beta instead of 2 beta). With the fix, the nonblank numbering tests pass (6/6), as do the UTF-16 integration tests (6/6). cargo fmt -- --check and cargo clippy --locked --all-targets --all-features -- -D warnings pass in rust:1.98-bookworm.

This change was prepared with AI assistance.

@keith-hall
keith-hall merged commit c231941 into sharkdp:master Nov 7, 2026
24 checks passed
cindykrafft pushed a commit to cindykrafft/bat that referenced this pull request Nov 7, 2026
Resolve the src/controller.rs conflict with sharkdp#4118: keep this branch's
plain line counter (blank-line handling for -b now lives in the printer,
which decodes UTF-16 before checking), and drop the ContentType and
UTF_16LE/BE imports that only sharkdp#4118's controller check used.
sharkdp#4118's CHANGELOG entry and number_nonblank_utf16 test are kept and pass.

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