mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
ls: use single quotes when $, \ or ` are present in a filename
This commit is contained in:
parent
d247cbd7e5
commit
67e7fdfc2e
1 changed files with 34 additions and 1 deletions
|
@ -283,7 +283,7 @@ pub(super) fn escape_name(name: &str, style: &QuotingStyle) -> String {
|
||||||
always_quote,
|
always_quote,
|
||||||
show_control,
|
show_control,
|
||||||
} => {
|
} => {
|
||||||
let (quotes, must_quote) = if name.contains('"') {
|
let (quotes, must_quote) = if name.contains(&['"', '`', '$', '\\'][..]) {
|
||||||
(Quotes::Single, true)
|
(Quotes::Single, true)
|
||||||
} else if name.contains('\'') {
|
} else if name.contains('\'') {
|
||||||
(Quotes::Double, true)
|
(Quotes::Double, true)
|
||||||
|
@ -690,4 +690,37 @@ mod tests {
|
||||||
);
|
);
|
||||||
check_names("name#", vec![("name#", "shell"), ("name#", "shell-escape")]);
|
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"),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue