mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
tests/ls: add coverage for special shell character after escaped char
This commit is contained in:
parent
795d89f11d
commit
f84f23ddfe
2 changed files with 32 additions and 4 deletions
|
@ -27,12 +27,10 @@ pub(super) enum Quotes {
|
||||||
// This implementation is heavily inspired by the std::char::EscapeDefault implementation
|
// This implementation is heavily inspired by the std::char::EscapeDefault implementation
|
||||||
// in the Rust standard library. This custom implementation is needed because the
|
// in the Rust standard library. This custom implementation is needed because the
|
||||||
// characters \a, \b, \e, \f & \v are not recognized by Rust.
|
// characters \a, \b, \e, \f & \v are not recognized by Rust.
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
struct EscapedChar {
|
struct EscapedChar {
|
||||||
state: EscapeState,
|
state: EscapeState,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
enum EscapeState {
|
enum EscapeState {
|
||||||
Done,
|
Done,
|
||||||
Char(char),
|
Char(char),
|
||||||
|
@ -41,14 +39,12 @@ enum EscapeState {
|
||||||
Octal(EscapeOctal),
|
Octal(EscapeOctal),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
struct EscapeOctal {
|
struct EscapeOctal {
|
||||||
c: char,
|
c: char,
|
||||||
state: EscapeOctalState,
|
state: EscapeOctalState,
|
||||||
idx: usize,
|
idx: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
enum EscapeOctalState {
|
enum EscapeOctalState {
|
||||||
Done,
|
Done,
|
||||||
Backslash,
|
Backslash,
|
||||||
|
@ -510,6 +506,23 @@ mod tests {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// A control character followed by a special shell character
|
||||||
|
check_names(
|
||||||
|
"one\n&two",
|
||||||
|
vec![
|
||||||
|
("one?&two", "literal"),
|
||||||
|
("one\n&two", "literal-show"),
|
||||||
|
("one\\n&two", "escape"),
|
||||||
|
("\"one\\n&two\"", "c"),
|
||||||
|
("'one?&two'", "shell"),
|
||||||
|
("'one\n&two'", "shell-show"),
|
||||||
|
("'one?&two'", "shell-always"),
|
||||||
|
("'one\n&two'", "shell-always-show"),
|
||||||
|
("'one'$'\\n''&two'", "shell-escape"),
|
||||||
|
("'one'$'\\n''&two'", "shell-escape-always"),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
// The first 16 control characters. NUL is also included, even though it is of
|
// The first 16 control characters. NUL is also included, even though it is of
|
||||||
// no importance for file names.
|
// no importance for file names.
|
||||||
check_names(
|
check_names(
|
||||||
|
|
|
@ -1190,6 +1190,21 @@ fn test_ls_quoting_style() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only(format!("{}\n", correct));
|
.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]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue