Skip to content

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

Closed

Description

@ChrisDryden

Description

When trying to come across edge cases in the non utf-8 fmt PR I came across that some outputs to fmt were not matching due to the line breaks being inserted in different places

Examples:


  $ printf 'aa bb cc dd ee' | /usr/bin/fmt -w 8
GNU
  aa
  bb cc
  dd ee

uutils
  aa bb cc
  dd ee


  $ printf '漢 字 test 日 本 語' | /usr/bin/fmt -w 10
GNU
  漢 字
  test 日
  本 語

uutils
  漢 字 test
  日 本 語


  $ printf '漢字 test 日本語' | /usr/bin/fmt -w 15
GNU
  漢字 test
  日本語

uutils
  $ printf '漢字 test 日本語' | uutils fmt -w 15
  漢字 test 日本語

Where to fix:

src/uu/fmt/src/linebreak.rs is the file that has the logic

Activity

  1. ChrisDryden commented on Jan 7, 2026

    @ChrisDryden
    CollaboratorAuthor

    This might be the same issue as this: #5162 but its not limited to the goal option, it also applied to -w

  2. pixelb commented on Jan 7, 2026

    @pixelb

    GNU fmt currently counts the \n as part of the count. That's confusing and inconsistent. I'll change that in the next couple of days. See GNU discussion

  3. elskow commented on Jan 7, 2026

    @elskow

    is this still up for grabs? I can take a take look at it.

    Also, re: @pixelb's note. I'm assuming we want to match the current GNU output for now despite the upcoming changes?

  4. ChrisDryden commented on Jan 8, 2026

    @ChrisDryden
    CollaboratorAuthor

    Yes I believe the goal is to target 1-1 compatibility with latest GNU

  5. shreysang commented on Mar 19, 2026

    @shreysang

    Hello, I'm a new contributor, is this issue up for grabs? I would love to take a look at this issue! Any general advice to get started would be appreciated

  6. mattiabandini1 commented on Mar 24, 2026

    @mattiabandini1

    Hi @Victor140108, are you currently working on this? If you haven't started yet or are busy with other things, I would love to take a look and try to fix it. Let me know!

  7. sankalpsthakur commented on Jul 30, 2026

    @sankalpsthakur
    Contributor

    I'd like to take this on.

    Quick retest against GNU fmt 9.11 (and current uutils main):

    • printf 'aa bb cc dd ee' | fmt -w 8 now matches on both sides (aa bb cc / dd ee) after GNU 9.10 stopped counting the trailing newline and after uutils #c138b386e.
    • The remaining mismatches are the CJK examples, where GNU still measures -w in UTF-8 bytes while uutils uses Unicode display columns.

    So I won't reopen the approach from #12623 (global width - 1 for explicit -w). Planning a narrower fix: count word/indent width in bytes like current GNU, with regression tests for the issue's examples. Happy to adjust if maintainers prefer staying on display-width ahead of GNU's planned multibyte work.

  8. added a commit that references this issue on Jul 30, 2026
    93025b5
  9. added a commit that references this issue on Sep 28, 2026
    e858a46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions