mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +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
|
||||
// in the Rust standard library. This custom implementation is needed because the
|
||||
// characters \a, \b, \e, \f & \v are not recognized by Rust.
|
||||
#[derive(Clone, Debug)]
|
||||
struct EscapedChar {
|
||||
state: EscapeState,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
enum EscapeState {
|
||||
Done,
|
||||
Char(char),
|
||||
|
@ -41,14 +39,12 @@ enum EscapeState {
|
|||
Octal(EscapeOctal),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct EscapeOctal {
|
||||
c: char,
|
||||
state: EscapeOctalState,
|
||||
idx: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
enum EscapeOctalState {
|
||||
Done,
|
||||
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
|
||||
// no importance for file names.
|
||||
check_names(
|
||||
|
|
|
@ -1190,6 +1190,21 @@ fn test_ls_quoting_style() {
|
|||
.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…
Reference in a new issue