Skip to content

Commit 12fb470

Browse files
committed
uucore/quoting_style: Add support for quoting/escaping empty strings
1 parent c5a236d commit 12fb470

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/uucore/src/lib/features/quoting_style.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ fn escape_name_inner(name: &[u8], style: &QuotingStyle, dirname: bool) -> Vec<u8
428428
(Quotes::Single, true)
429429
} else if name.contains(&b'\'') {
430430
(Quotes::Double, true)
431-
} else if *always_quote {
431+
} else if *always_quote || name.is_empty() {
432432
(Quotes::Single, true)
433433
} else {
434434
(Quotes::Single, false)
@@ -609,6 +609,25 @@ mod tests {
609609
);
610610
}
611611

612+
#[test]
613+
fn test_empty_string() {
614+
check_names(
615+
"",
616+
&[
617+
("", "literal"),
618+
("", "literal-show"),
619+
("", "escape"),
620+
("\"\"", "c"),
621+
("''", "shell"),
622+
("''", "shell-show"),
623+
("''", "shell-always"),
624+
("''", "shell-always-show"),
625+
("''", "shell-escape"),
626+
("''", "shell-escape-always"),
627+
],
628+
);
629+
}
630+
612631
#[test]
613632
fn test_spaces() {
614633
check_names(

0 commit comments

Comments
 (0)