Skip to content

expand, unexpand: preserve bare - as stdin - #15716

Open
qiyuhuating wants to merge 5 commits into
uutils:mainfrom
qiyuhuating:fix/expand-unexpand-bare-stdin
Open

qiyuhuating wants to merge 5 commits into
uutils:mainfrom
qiyuhuating:fix/expand-unexpand-bare-stdin

Conversation

@qiyuhuating

Copy link
Copy Markdown

Fixes #15658.

expand_shortcuts() handles obsolete -N tab-stop syntax before clap sees the operands. A bare - also matched that check because the part after - is empty and Iterator::all() returns true for an empty iterator.

For expand, this removes the stdin operand from a multi-file command. For unexpand, it additionally marks a shortcut as present and appends --first-only, changing -t N - behavior.

Require at least one character after the leading - before recognizing an obsolete tab-stop shortcut. A bare - therefore reaches clap as the normal stdin file operand.

Tests cover stdin before another FILE for both utilities and ensure unexpand -t 3 - does not accidentally enable --first-only.

This is independent of #14291, which handles hyphen-leading values passed to -t; a bare - in normal operand position remains a separate case.

Comment thread src/uu/unexpand/src/unexpand.rs Outdated
if let Some(arg) = arg.to_str() {
if arg.starts_with('-') && arg[1..].chars().all(is_digit_or_comma) {
if arg.len() > 1
&& arg.starts_with('-')

This comment was marked as resolved.

@qiyuhuating
qiyuhuating force-pushed the fix/expand-unexpand-bare-stdin branch from 28855ba to 0bca20e Compare October 24, 2026 14:25
#[test]
fn test_bare_dash_does_not_force_first_only() {
new_ucmd!()
.args(&["-t", "3", "-"])

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 you please also add --first-only -? it was failing with "cannot be used multiple times" in the issue

@qiyuhuating

Copy link
Copy Markdown
Author

Thanks @oech3 and @sylvestre for the reviews.

I've updated both expand and unexpand to use strip_prefix('-') and added a regression test for unexpand --first-only - in abf8b37.

Both suggestions are addressed now. Thanks again!

This branch has not been deployed

No deployments
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.

expand/unexpand: a bare - operand is taken as an obsolete -N tab option, so standard input is skipped

3 participants