Skip to content

unexpand: resume tab conversion when backspaces move before last tab stop - #16159

Merged
cakebaker merged 1 commit into
uutils:mainfrom
huuan26:fix/unexpand-backspace-tab-conversion-16120
Nov 3, 2026
Merged

cakebaker merged 1 commit into
uutils:mainfrom
huuan26:fix/unexpand-backspace-tab-conversion-16120

Conversation

@huuan26

@huuan26 huuan26 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #16120

Summary

When unexpanding with a finite tab-stop list (e.g. -t 3,5), \unexpand_buf\ previously fast-forwarded and dumped the remaining buffer as soon as \print_state.col >= lastcol. However, if subsequent backspaces (\b) occurred in the buffer, the column would move back below \lastcol, where spaces should once again be converted to tabs according to GNU \unexpand.

This PR ensures we only fast-forward when the remaining buffer does not contain backspaces (!buf[byte..].contains(&b'\x08')), allowing backspaces to decrease the column and resume tab conversion as expected.

Verification

Added test case in \ ests/by-util/test_unexpand.rs\ with input \�bcde\b\b X\n\ and -t 3,5, verifying that the two spaces are converted to a tab (\t), matching GNU coreutils.
All tests pass.

@cakebaker
cakebaker force-pushed the fix/unexpand-backspace-tab-conversion-16120 branch from 5a5c713 to 124a476 Compare November 3, 2026 08:42
@cakebaker
cakebaker merged commit c6367b8 into uutils:main Nov 3, 2026
99 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Thanks!

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.

unexpand: backspaces before the last tab stop do not resume tab conversion

2 participants