From 47e908bc6cbd40c9a937ed8f78dc384c83ff2b42 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 10 Jan 2024 18:59:33 +0100 Subject: [PATCH] printf: output of double-quote should not be escaped This is obtained by escaping the sequence `\"` as `"`. --- src/uucore/src/lib/features/format/escape.rs | 1 + tests/by-util/test_printf.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/uucore/src/lib/features/format/escape.rs b/src/uucore/src/lib/features/format/escape.rs index d20da3e7e..9420507f3 100644 --- a/src/uucore/src/lib/features/format/escape.rs +++ b/src/uucore/src/lib/features/format/escape.rs @@ -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, diff --git a/tests/by-util/test_printf.rs b/tests/by-util/test_printf.rs index 48fc1e6ac..a288d7c08 100644 --- a/tests/by-util/test_printf.rs +++ b/tests/by-util/test_printf.rs @@ -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");