mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Merge pull request #7693 from sargas/escape_empty_string
uucore/quoting_style: Add support for quoting/escaping empty strings
This commit is contained in:
commit
c35d26dc51
2 changed files with 25 additions and 1 deletions
|
@ -428,7 +428,7 @@ fn escape_name_inner(name: &[u8], style: &QuotingStyle, dirname: bool) -> Vec<u8
|
||||||
(Quotes::Single, true)
|
(Quotes::Single, true)
|
||||||
} else if name.contains(&b'\'') {
|
} else if name.contains(&b'\'') {
|
||||||
(Quotes::Double, true)
|
(Quotes::Double, true)
|
||||||
} else if *always_quote {
|
} else if *always_quote || name.is_empty() {
|
||||||
(Quotes::Single, true)
|
(Quotes::Single, true)
|
||||||
} else {
|
} else {
|
||||||
(Quotes::Single, false)
|
(Quotes::Single, false)
|
||||||
|
@ -609,6 +609,25 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_empty_string() {
|
||||||
|
check_names(
|
||||||
|
"",
|
||||||
|
&[
|
||||||
|
("", "literal"),
|
||||||
|
("", "literal-show"),
|
||||||
|
("", "escape"),
|
||||||
|
("\"\"", "c"),
|
||||||
|
("''", "shell"),
|
||||||
|
("''", "shell-show"),
|
||||||
|
("''", "shell-always"),
|
||||||
|
("''", "shell-always-show"),
|
||||||
|
("''", "shell-escape"),
|
||||||
|
("''", "shell-escape-always"),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_spaces() {
|
fn test_spaces() {
|
||||||
check_names(
|
check_names(
|
||||||
|
|
|
@ -242,6 +242,11 @@ fn sub_q_string_special_non_printable() {
|
||||||
.stdout_only("non-printable: test~");
|
.stdout_only("non-printable: test~");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sub_q_string_empty() {
|
||||||
|
new_ucmd!().args(&["%q", ""]).succeeds().stdout_only("''");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sub_char() {
|
fn sub_char() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue