Skip to content

ls: fix //DIRED-OPTIONS// printing the wrong quoting-style name - #14847

Merged
sylvestre merged 2 commits into
uutils:mainfrom
alter:fix/dired-quoting-style-name
Sep 28, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
alter:fix/dired-quoting-style-name

Conversation

@alter

@alter alter commented Sep 24, 2026

Copy link
Copy Markdown

Fixes #14775

What

GNU ls --dired ends its output with //DIRED-OPTIONS// --quoting-style=<name>, where <name> is the canonical name of the quoting style in effect (literal, shell, shell-always, shell-escape, shell-escape-always, c, escape, locale, clocale). uutils was printing the Display form of the internal QuotingStyle enum instead, which gets most of these wrong: several distinct style names collapse onto the same enum shape (c, escape and clocale all reduce to QuotingStyle::C; literal and locale both reduce to QuotingStyle::Literal), and the Display impl also appends a -show-control/-always-quote suffix that the --dired trailer never uses (those describe separate ls options, not part of the quoting-style name).

Why

Display for QuotingStyle is used elsewhere and reconstructs a name purely from the enum's own fields, so it can't tell c from escape from clocale, or literal from locale. The extra bit needed to disambiguate the locale-aware pair already exists on Config as locale_quoting: Option<LocaleQuoting> (set during option parsing), it just wasn't being consulted for the dired trailer.

Fix

Added dired_quoting_style_name() in src/uu/ls/src/dired.rs, used only for the //DIRED-OPTIONS// line. It checks config.locale_quoting first (disambiguates locale/clocale), then matches on config.quoting_style's own fields directly: the Quotes field on the C variant already distinguishes c (Quotes::Double) from escape (Quotes::None), and the (escape, always_quote) fields on Shell map directly to the four shell style names, with no show_control/-show-control suffix.

Testing

Added test_ls_dired_quoting_style_name to tests/by-util/test_ls.rs, covering all 9 --quoting-style=<name> values plus the -N/-Q/-b short flags, checking the exact //DIRED-OPTIONS// line against the canonical GNU name from the issue's own table. Confirmed it fails against unmodified dired.rs (e.g. --quoting-style=c prints --quoting-style=C) and passes after the fix.

cargo test --features ls (dired + quoting-style tests): 21/21 dired tests and 7/7 dired module unit tests passing, no regressions. cargo clippy -p uu_ls --all-targets -- -D warnings: clean. cargo fmt --check: clean.

Also manually verified all 9 styles plus the 3 short flags against a built binary, matching the issue's own reproduction table exactly.

Comment thread src/uu/ls/src/dired.rs
Ok(())
}

/// The canonical `--quoting-style` name for the `//DIRED-OPTIONS//` trailer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nobody will read such a long comment :) could you please make it one or two lines?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nobody but yesagent

Comment thread tests/by-util/test_ls.rs Outdated
.stdout_contains("//DIRED-OPTIONS// --quoting-style");
}

// Regression test for issue #14775: //DIRED-OPTIONS// must report the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make it shorter, the issue link is enough

@RenjiSann

Copy link
Copy Markdown
Collaborator

This PR conflicts with #14849, which heavily refactors quoting mechanisms. I'd advise to refrain from merging it for now

@alter
alter force-pushed the fix/dired-quoting-style-name branch from a40ef98 to ee81d2e Compare September 27, 2026 21:59
@sylvestre
sylvestre merged commit c1883e1 into uutils:main Sep 28, 2026
98 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

@RenjiSann

Copy link
Copy Markdown
Collaborator

@sylvestre Can I take over the quoting_style matter ? I've been working on a large refactor for the past few days at #14849, but small utils-specific patches like this one keep being merged (#14885 before this one), giving me extra rebase-intensive workload :/

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 --dired prints wrong quoting style name in //DIRED-OPTIONS//

4 participants