Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.