diff --git a/src/uu/ls/src/quoting_style.rs b/src/uu/ls/src/quoting_style.rs index fd5cab57e..c4c8200a4 100644 --- a/src/uu/ls/src/quoting_style.rs +++ b/src/uu/ls/src/quoting_style.rs @@ -1,6 +1,6 @@ use std::char::from_digit; -const SPECIAL_SHELL_CHARS: &str = "~`#$&*()|[]{};'\"<>?! "; +const SPECIAL_SHELL_CHARS: &str = "~`#$&*()|[]{};\\'\"<>?! "; pub(super) enum QuotingStyle { Shell { diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index d44074821..718e1db1c 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -1118,12 +1118,13 @@ 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. + // And it also doesn't like \, of course. #[cfg(unix)] { at.touch("one\ntwo"); + at.touch("one\\two"); // Default is shell-escape scene .ucmd() @@ -1185,6 +1186,42 @@ 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)); + } + + // Tests for a character that forces quotation in shell-style escaping + // after a character in a dollar expression + at.touch("one\n&two"); + for (arg, correct) in &[ + ("--quoting-style=shell-escape", "'one'$'\\n''&two'"), + ("--quoting-style=shell-escape-always", "'one'$'\\n''&two'"), + ] { + scene + .ucmd() + .arg(arg) + .arg("one\n&two") + .succeeds() + .stdout_only(format!("{}\n", correct)); + } } scene @@ -1238,42 +1275,6 @@ 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)); - } - - // Tests for a character that forces quotation in shell-style escaping - // after a character in a dollar expression - at.touch("one\n&two"); - for (arg, correct) in &[ - ("--quoting-style=shell-escape", "'one'$'\\n''&two'"), - ("--quoting-style=shell-escape-always", "'one'$'\\n''&two'"), - ] { - scene - .ucmd() - .arg(arg) - .arg("one\n&two") - .succeeds() - .stdout_only(format!("{}\n", correct)); - } } #[test]