Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/uucore/src/lib/features/quoting_style/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,16 @@ mod tests {
("'can'\\''\\t'", "shell-escape-always"),
],
);

check_names_both(
"can'!t",
&[
("'can'\\''!t'", "shell"),
("'can'\\''!t'", "shell-always"),
("'can'\\''!t'", "shell-escape"),
("'can'\\''!t'", "shell-escape-always"),
],
);
}

#[test]
Expand Down
18 changes: 17 additions & 1 deletion src/uucore/src/lib/features/quoting_style/shell_quoter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ fn bytes_start_with(bytes: &[u8], pattern: &[u8]) -> bool {
/// Return a set of characters that implies quoting of the word in
/// shell-quoting mode.
fn shell_escaped_char_set(is_dirname: bool) -> &'static [u8] {
const ESCAPED_CHARS: &[u8] = b":\"`$\\^\n\t\r=";
const ESCAPED_CHARS: &[u8] = b":\"`$\\^\n\t\r=!";
// the ':' colon character only induce quoting in the
// context of ls displaying a directory name before listing its content.
// (e.g. with the recursive flag -R)
Expand Down Expand Up @@ -299,6 +299,22 @@ mod tests {
(ShellQuotes::Double, true)
);

// Simple quote uses double quotes in non-escape mode
assert_eq!(
initial_quoting(b"a'b", false, false, false),
(ShellQuotes::Double, true)
);

// `!` is history-expanded inside double quotes, so a quote with `!` uses single quotes
assert_eq!(
initial_quoting(b"a'!b", false, false, true),
(ShellQuotes::Single, true)
);
assert_eq!(
initial_quoting(b"a'!b", false, false, false),
(ShellQuotes::Single, true)
);

// Shell special chars force single quotes in escape mode
assert_eq!(
initial_quoting(b"test$var", false, false, true),
Expand Down
18 changes: 18 additions & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3080,6 +3080,24 @@ mod quoting {
);
}

#[test]
fn test_ls_quoting_single_quote_exclamation() {
check_quoting_dirname(
"dir'!name",
&[
("shell", "'dir'\\''!name'", "'./dir'\\''!name'"),
("shell-always", "'dir'\\''!name'", "'./dir'\\''!name'"),
("shell-escape", "'dir'\\''!name'", "'./dir'\\''!name'"),
(
"shell-escape-always",
"'dir'\\''!name'",
"'./dir'\\''!name'",
),
],
&[],
);
}

#[test]
fn test_ls_quoting_double_quote() {
check_quoting_dirname(
Expand Down
1 change: 1 addition & 0 deletions tests/by-util/test_printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use uutests::new_ucmd;
#[case::sub_q_string_non_printable(&["non-printable: %q", "\"$test\""], "non-printable: '\"$test\"'")]
#[case::sub_q_string_special_non_printable(&["non-printable: %q", "test~"], "non-printable: test~")]
#[case::sub_q_string_empty(&["%q", ""], "''")]
#[case::sub_q_string_quote_and_bang(&["%q", "a'!b"], "'a'\\''!b'")]
#[case::sub_char(&["the letter %c", "A"], "the letter A")]
#[case::sub_char_from_string(&["%c%c%c", "five", "%", "oval"], "f%o")]
#[case::sub_num_int(&["twenty is %i", "20"], "twenty is 20")]
Expand Down
Loading