Skip to content

uucore(mode): quote the offending character in invalid operator errors - #15409

Open
henrimarconni wants to merge 1 commit into
uutils:mainfrom
henrimarconni:mkdir-quote-invalid-mode
Open

henrimarconni wants to merge 1 commit into
uutils:mainfrom
henrimarconni:mkdir-quote-invalid-mode

Conversation

@henrimarconni

Copy link
Copy Markdown
Contributor

Fixes #15350

mkdir -m $'\xC2\xAF' c currently prints the offending character bare:

mkdir: invalid operator (expected +, -, or =, but found ¯)

With odd or non-ASCII characters it's hard to tell what you're looking at, so I wrapped it in single quotes:

mkdir: invalid operator (expected +, -, or =, but found '¯')

The message template lives in uucore, so chmod gets the same change. I updated the two existing tests that checked the old text (chmod and mkdir) and added a mkdir test for the non-ASCII case from the issue.

One thing to flag: GNU says invalid mode '¯' instead of our "invalid operator (...)" wording. I only fixed the quoting here and left the wording alone, since it's tied to the caret diagnostic.

(Side note: the issue title says mv, but the repro is mkdir.)

Tested with cargo fmt, cargo clippy -p uucore -p uu_mkdir, and cargo test -p uucore -p uu_mkdir -p uu_chmod.

@codspeed

codspeed Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 72 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 124 untouched benchmarks
⏩ 361 skipped benchmarks1


Comparing henrimarconni:mkdir-quote-invalid-mode (071c255) with main (ab69b86)

Open in CodSpeed

Footnotes

  1. 361 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@sylvestre

Copy link
Copy Markdown
Contributor

the CI has been failing on this one for a while, could you please have a look? otherwise, i will close it, thanks

@sylvestre
sylvestre force-pushed the mkdir-quote-invalid-mode branch from 30f906e to ecceb47 Compare November 26, 2026 05:19
@henrimarconni

Copy link
Copy Markdown
Contributor Author

Sorry for the late reply, I'll fix the failing checks and update the PR shortly.

@sylvestre
sylvestre force-pushed the mkdir-quote-invalid-mode branch from ecceb47 to ad669aa Compare November 27, 2026 10:22
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

ucmd.args(&["g+rw?x", "probe"])
.fails_with_code(1)
.stderr_only("chmod: invalid operator (expected +, -, or =, but found ?)\n");
.stderr_only("chmod: invalid operator (expected +, -, or =, but found '?')\n");

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.

test_chmod_invalid_mode_checked_before_any_file (line 1408) still expects the old message, please update it too


assert!(
stderr.contains("invalid operator (expected +, -, or =, but found \\001)"),
stderr.contains("invalid operator (expected +, -, or =, but found '\\001)'"),

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.

the quote is misplaced, should be '\\001'), that's why CI is red

fn test_invalid_mode_operator_is_quoted() {
let (_, mut ucmd) = at_and_ucmd!();
ucmd.args(&["-m", "\u{AF}", "c"])
.fails()

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 use fails_with_code(1) and stderr_only like the other tests?

@sylvestre

Copy link
Copy Markdown
Contributor

clippy is sad :), and a bunch of jobs are failing

@sylvestre
sylvestre force-pushed the mkdir-quote-invalid-mode branch from ad669aa to 071c255 Compare November 27, 2026 18:26
@sylvestre
sylvestre force-pushed the mkdir-quote-invalid-mode branch from 071c255 to 8d1460e Compare November 27, 2026 22:27

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.

2 participants