mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
ls: always quote backslash in shell style
This commit is contained in:
parent
fd54614130
commit
f34c992932
2 changed files with 39 additions and 38 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 {
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue