Skip to content

quoting: use single quotes for apostrophe names with C1 controls - #15878

Open
fixfon wants to merge 1 commit into
uutils:mainfrom
fixfon:fix/15810-c1-control-apostrophe
Open

fixfon wants to merge 1 commit into
uutils:mainfrom
fixfon:fix/15810-c1-control-apostrophe

Conversation

@fixfon

@fixfon fixfon commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #15810

In the shell-escape styles, a name that has an apostrophe and a C1 control character (U+0080 to U+009F) was printed as one double-quoted word that contains a $'\302\233' segment. A shell does not expand $'...' inside double quotes, so the word named a different file. For it's followed by U+009B and here, printf %q printed "it's'$'\302\233''here". ls --quoting-style=shell-escape, ls --quoting-style=shell-escape-always and stat -c %N printed the same word.

EscapedShellQuoter::new switches to single quotes when the name is not valid in the locale encoding, because only then did it expect a $'...' segment. A valid C1 character is also written that way, so the check missed it. The check now asks EscapedChar::new_shell, which writes the segment, so the two cannot drift apart. The word is now 'it'\''s'$'\302\233''here'.

I added a unit test in quoting_style and a printf %q test in test_printf.rs. Both fail on current main and pass with this change. cargo fmt passes, cargo clippy --all-targets -- -D warnings passes, and the uucore tests and test_ls, test_printf and test_stat pass, except test_ls_indicator_style, which fails the same way on main in my setup because of a long socket path on macOS. Tested on macOS only.

A shell-escape name with an apostrophe stays in double quotes unless it
holds invalid bytes. Valid control characters outside ASCII, such as the
C1 controls, are also written as $'...' segments, which are plain text
inside double quotes, so the quoted word named a different file. Use
single quotes whenever a character is escaped that way, by asking the
function that escapes it.

Fixes uutils#15810

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.

quoting_style: shell-escape misquotes C1 controls in names with an apostrophe

1 participant