mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +00:00
ls: don't escape backslash in shell style quoting
This commit is contained in:
parent
ff620b5fa4
commit
795d89f11d
2 changed files with 41 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::char::from_digit;
|
||||
|
||||
const SPECIAL_SHELL_CHARS: &str = "~`#$&*()\\|[]{};'\"<>?! ";
|
||||
const SPECIAL_SHELL_CHARS: &str = "~`#$&*()|[]{};'\"<>?! ";
|
||||
|
||||
pub(super) enum QuotingStyle {
|
||||
Shell {
|
||||
|
@ -135,7 +135,6 @@ impl EscapedChar {
|
|||
'\x0B' => Backslash('v'),
|
||||
'\x0C' => Backslash('f'),
|
||||
'\r' => Backslash('r'),
|
||||
'\\' => Backslash('\\'),
|
||||
'\x00'..='\x1F' | '\x7F' => Octal(EscapeOctal::from(c)),
|
||||
'\'' => match quotes {
|
||||
Quotes::Single => Backslash('\''),
|
||||
|
@ -627,4 +626,22 @@ mod tests {
|
|||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_backslash() {
|
||||
// Escaped in C-style, but not in Shell-style escaping
|
||||
check_names(
|
||||
"one\\two",
|
||||
vec![
|
||||
("one\\two", "literal"),
|
||||
("one\\two", "literal-show"),
|
||||
("one\\\\two", "escape"),
|
||||
("\"one\\\\two\"", "c"),
|
||||
("one\\two", "shell"),
|
||||
("\'one\\two\'", "shell-always"),
|
||||
("one\\two", "shell-escape"),
|
||||
("'one\\two'", "shell-escape-always"),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1049,6 +1049,7 @@ fn test_ls_quoting_style() {
|
|||
|
||||
at.touch("one two");
|
||||
at.touch("one");
|
||||
at.touch("one\\two");
|
||||
|
||||
// It seems that windows doesn't allow \n in filenames.
|
||||
#[cfg(unix)]
|
||||
|
@ -1168,6 +1169,27 @@ fn test_ls_quoting_style() {
|
|||
.succeeds()
|
||||
.stdout_only(format!("{}\n", correct));
|
||||
}
|
||||
|
||||
for (arg, correct) in &[
|
||||
("--quoting-style=literal", "one\\two"),
|
||||
("-N", "one\\two"),
|
||||
("--quoting-style=c", "\"one\\\\two\""),
|
||||
("-Q", "\"one\\\\two\""),
|
||||
("--quote-name", "\"one\\\\two\""),
|
||||
("--quoting-style=escape", "one\\\\two"),
|
||||
("-b", "one\\\\two"),
|
||||
("--quoting-style=shell-escape", "one\\two"),
|
||||
("--quoting-style=shell-escape-always", "'one\\two'"),
|
||||
("--quoting-style=shell", "one\\two"),
|
||||
("--quoting-style=shell-always", "'one\\two'"),
|
||||
] {
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(arg)
|
||||
.arg("one\\two")
|
||||
.succeeds()
|
||||
.stdout_only(format!("{}\n", correct));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue