Skip to content

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

Merged
sylvestre merged 2 commits into
uutils:mainfrom
fixfon:fix/15810-c1-control-apostrophe
Nov 2, 2026
Merged

sylvestre merged 2 commits 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.

}

#[test]
fn test_q_string_c1_control_char_with_quote() {

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.

maybe also add a ls --quoting-style=shell-escape test? the issue reports it there too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a test_ls case for shell-escape with a C1 control and an apostrophe, in b6e2ce3.

@codspeed

codspeed Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning, 1 note

⚠️ 123 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

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

✅ 401 untouched benchmarks
⏩ 70 skipped benchmarks1


Comparing fixfon:fix/15810-c1-control-apostrophe (b5498cf) with main (9cc868b)2

Open in CodSpeed

Footnotes

  1. 70 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. ↩

  2. No successful run was found on main (ddc71a4) during the generation of this report, so 9cc868b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

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
@sylvestre
sylvestre force-pushed the fix/15810-c1-control-apostrophe branch from b6e2ce3 to b5498cf Compare November 1, 2026 17:56
@sylvestre
sylvestre merged commit 6201c4f into uutils:main Nov 2, 2026
189 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.

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

2 participants