Repository navigation
quoting: use single quotes for apostrophe names with C1 controls - #15878
Conversation
| } | ||
|
|
||
| #[test] | ||
| fn test_q_string_c1_control_char_with_quote() { |
There was a problem hiding this comment.
maybe also add a ls --quoting-style=shell-escape test? the issue reports it there too
There was a problem hiding this comment.
Added a test_ls case for shell-escape with a C1 control and an apostrophe, in b6e2ce3.
Merging this PR will not alter performance1 warning, 1 note
Comparing Footnotes
|
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
b6e2ce3 to
b5498cf
Compare
|
Thanks for your PR |
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. Forit'sfollowed by U+009B andhere,printf %qprinted"it's'$'\302\233''here".ls --quoting-style=shell-escape,ls --quoting-style=shell-escape-alwaysandstat -c %Nprinted the same word.EscapedShellQuoter::newswitches 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 asksEscapedChar::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_styleand aprintf %qtest intest_printf.rs. Both fail on current main and pass with this change.cargo fmtpasses,cargo clippy --all-targets -- -D warningspasses, and the uucore tests andtest_ls,test_printfandtest_statpass, excepttest_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.