1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #2622 from tertsdiepraam/ls/special-chars-in-double-quotes

`ls`: always use single quotes when `$`, `\` or ` are present in a filename
This commit is contained in:
Sylvestre Ledru 2021-09-07 22:04:48 +02:00 committed by GitHub
commit ff5607c363
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -287,7 +287,7 @@ pub(super) fn escape_name(name: &OsStr, style: &QuotingStyle) -> String {
show_control,
} => {
let name = name.to_string_lossy();
let (quotes, must_quote) = if name.contains('"') {
let (quotes, must_quote) = if name.contains(&['"', '`', '$', '\\'][..]) {
(Quotes::Single, true)
} else if name.contains('\'') {
(Quotes::Double, true)
@ -694,4 +694,37 @@ mod tests {
);
check_names("name#", vec![("name#", "shell"), ("name#", "shell-escape")]);
}
#[test]
fn test_special_chars_in_double_quotes() {
check_names(
"can'$t",
vec![
("'can'\\''$t'", "shell"),
("'can'\\''$t'", "shell-always"),
("'can'\\''$t'", "shell-escape"),
("'can'\\''$t'", "shell-escape-always"),
],
);
check_names(
"can'`t",
vec![
("'can'\\''`t'", "shell"),
("'can'\\''`t'", "shell-always"),
("'can'\\''`t'", "shell-escape"),
("'can'\\''`t'", "shell-escape-always"),
],
);
check_names(
"can'\\t",
vec![
("'can'\\''\\t'", "shell"),
("'can'\\''\\t'", "shell-always"),
("'can'\\''\\t'", "shell-escape"),
("'can'\\''\\t'", "shell-escape-always"),
],
);
}
}