Skip to content

Commit

Permalink
printf: output of double-quote should not be escaped
Browse files Browse the repository at this point in the history
This is obtained by escaping the sequence `\"` as `"`.
  • Loading branch information
samueltardieu committed Jan 10, 2024
1 parent 0071442 commit 47e908b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/uucore/src/lib/features/format/escape.rs
Expand Up @@ -108,6 +108,7 @@ pub fn parse_escape_code(rest: &mut &[u8]) -> EscapedChar {
*rest = new_rest;
match c {
b'\\' => EscapedChar::Byte(b'\\'),
b'"' => EscapedChar::Byte(b'"'),
b'a' => EscapedChar::Byte(b'\x07'),
b'b' => EscapedChar::Byte(b'\x08'),
b'c' => EscapedChar::End,
Expand Down
5 changes: 5 additions & 0 deletions tests/by-util/test_printf.rs
Expand Up @@ -36,6 +36,11 @@ fn escaped_slash() {
.stdout_only("hello\\ world");
}

#[test]
fn unescaped_double_quote() {
new_ucmd!().args(&["\\\""]).succeeds().stdout_only("\"");
}

#[test]
fn escaped_hex() {
new_ucmd!().args(&["\\x41"]).succeeds().stdout_only("A");
Expand Down

0 comments on commit 47e908b

Please sign in to comment.