Skip to content

fmt: preserve leading equals in short prefix options - #15474

Merged
sylvestre merged 1 commit into
uutils:mainfrom
limadog9:fix/fmt-equals-prefix-6353
Oct 23, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
limadog9:fix/fmt-equals-prefix-6353

Conversation

@limadog9

Copy link
Copy Markdown
Contributor

Clap strips a leading equals sign from attached short-option values, but fmt treats it as part of the prefix. Preserve it for -p and -P, including grouped flags, while leaving long options, other values, and operands after -- unchanged.

Enable the existing regressions and cover overrides, repeated equals, and prefixes that contain option spellings.

Closes #6353.

@limadog9
limadog9 force-pushed the fix/fmt-equals-prefix-6353 branch from cc59c13 to 84057f1 Compare October 18, 2026 14:59
Comment thread src/uu/fmt/src/fmt.rs Outdated
if arg == "--" {
break;
}
let Some(value) = arg.to_str() else {

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.

non-UTF-8 args are skipped here, so -p= followed by invalid bytes still loses the =.
could you work on as_encoded_bytes() instead? and please add a test for it

Comment thread src/uu/fmt/src/fmt.rs Outdated
}
break;
}
'c' | 't' | 'm' | 's' | 'u' | 'x' | 'X' | 'q' => {}

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.

this duplicates the flag list from uu_app(), it will get out of sync when a flag is added.
could we build it from uu_app().get_arguments() (the SetTrue ones) instead?

@limadog9
limadog9 force-pushed the fix/fmt-equals-prefix-6353 branch from 84057f1 to 7edd7ad Compare October 18, 2026 22:00
Comment thread src/uu/fmt/src/fmt.rs Outdated
}
}

#[cfg(all(test, unix))]

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.

could this go in the existing mod tests with a #[cfg(unix)] on the test instead of a new module?

Clap strips a leading equals sign from attached short-option values, but
fmt treats it as part of the prefix. Preserve it for -p and -P, including
grouped flags, while leaving long options, other values, and operands after
-- unchanged.

Enable the existing regressions and cover overrides, repeated equals, and
prefixes that contain option spellings.

Closes uutils#6353.
@limadog9
limadog9 force-pushed the fix/fmt-equals-prefix-6353 branch from 7edd7ad to 4268474 Compare October 19, 2026 19:28
@sylvestre
sylvestre merged commit 5ded260 into uutils:main Oct 23, 2026
98 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

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: clap causes information loss

2 participants