Skip to content

fmt: match GNU wrapping for explicit widths - #12623

Closed
wondr-wclabs wants to merge 1 commit into
uutils:mainfrom
wondr-wclabs:codex/fmt-gnu-line-wrapping
Closed

wondr-wclabs wants to merge 1 commit into
uutils:mainfrom
wondr-wclabs:codex/fmt-gnu-line-wrapping

Conversation

@wondr-wclabs

Copy link
Copy Markdown
Contributor

Fixes #10095.

GNU fmt counts the terminating newline against an explicit -w/--width value, so the visible line content budget is one column lower than the user-supplied width. uutils was using the full width as visible content budget, which allowed lines such as aa bb cc at -w 8 and kept some wide-character examples on one line where GNU wraps earlier.

This keeps validation against the user-supplied width first, then adjusts only the internal line-breaking width/goal for explicit widths. The default width path stays unchanged.

The regression coverage uses the ASCII and Unicode examples from the issue so the intended GNU-compatible wrapping is visible in tests.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/fmt/width. tests/fmt/width is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/dd/no-allocate is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!

@pixelb

pixelb commented Jun 5, 2026

Copy link
Copy Markdown

I wouldn't apply this as GNU fmt 9.10 was changed to not including the newline in the count.
Also GNU fmt will change soon to correctly determining the width of multi-byte characters

@wondr-wclabs

Copy link
Copy Markdown
Contributor Author

Thanks for the context. I agree this should not land as-is. The PR was targeting the older observed GNU behavior from #10095 where explicit widths effectively lost one visible column to the terminating newline, but that direction is now stale if GNU fmt 9.10 no longer counts the newline and upstream is also about to improve multibyte width handling. The failing comparison is a good signal that this patch would move uutils toward behavior GNU no longer wants to preserve. Closing this PR rather than trying to paper over that failure. A better follow-up would be to retest #10095 against current GNU fmt and then make a narrower patch around the remaining multibyte display-width differences, if any, instead of adjusting the explicit width budget globally.

@wondr-wclabs

Copy link
Copy Markdown
Contributor Author

Small correction to my previous comment: the failing comparison I meant was tests/fmt/width, which is exactly the GNU test that exercises this wrapping behavior. That reinforces the reason for closing this PR rather than trying to keep the global width-budget adjustment.

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.

fmt: line-wrapping differs from gnu implementation in some situations

2 participants