Skip to content

ls: fix leading space before first entry when color is enabled#12435

Open
hz2 wants to merge 1 commit into
uutils:mainfrom
hz2:fix/ls-color-leading-space
Open

ls: fix leading space before first entry when color is enabled#12435
hz2 wants to merge 1 commit into
uutils:mainfrom
hz2:fix/ls-color-leading-space

Conversation

@hz2
Copy link
Copy Markdown
Contributor

@hz2 hz2 commented May 22, 2026

Summary

  • When --color is active and quoting is in use, entry names get wrapped in ANSI escape sequences. The alignment logic that prepends a space to unquoted entries was checking the raw first byte of the name, which is now an ESC character instead of a quote. This caused a spurious leading space on every output line in columnar mode.
  • Added a helper that skips over ANSI CSI sequences before checking whether a name starts with a quote character, and used it in both the grid format and long format code paths.
  • Added a regression test that asserts no leading space appears when all names are quoted and color is enabled.

Fixes #12432

Test plan

  • Reproduced the bug using the exact steps from the issue (script + perl byte check)
  • Verified output now matches GNU coreutils 9.9 byte for byte
  • Confirmed the alignment space still works correctly for mixed quoted/unquoted names
  • All 165 existing ls tests pass with no regressions
  • New test covers the specific scenario from the issue

When --color is active and quoting is used, entry names are wrapped in
ANSI escape sequences. The alignment logic that prepends a space to
unquoted names was checking the raw first byte, which is now an ESC
character rather than a quote. This caused a spurious leading space on
every output line.

Skip over ANSI CSI sequences before checking whether the name starts
with a quote character.

Fixes uutils#12432
@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/misc/io-errors (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/retry (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout-group (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/pid-pipe (passes in this run but fails in the 'main' branch)

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.

ls: --color=always adds a leading space before first entry on each output line

1 participant