From 3ce67ecbd2348fbe13e86a00bea6ce998710729a Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 5 Oct 2023 15:39:50 +0200 Subject: [PATCH] printf: Fix octal escapes with leading zeroes Octal escapes can be written as `\057` or as `\0057`. Simply ported wrong initially. --- fish-rust/src/builtins/printf.rs | 2 +- tests/checks/printf.fish | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fish-rust/src/builtins/printf.rs b/fish-rust/src/builtins/printf.rs index 9de048a4e..167dd4d06 100644 --- a/fish-rust/src/builtins/printf.rs +++ b/fish-rust/src/builtins/printf.rs @@ -698,7 +698,7 @@ fn print_esc_string(&mut self, mut str: &wstr) { while !str.is_empty() { let c = str.char_at(0); if c == '\\' { - let consumed_minus_1 = self.print_esc(str, false); + let consumed_minus_1 = self.print_esc(str, true); str = &str[consumed_minus_1..]; } else { self.append_output(c); diff --git a/tests/checks/printf.fish b/tests/checks/printf.fish index cbedab18d..f1cc238e1 100644 --- a/tests/checks/printf.fish +++ b/tests/checks/printf.fish @@ -147,3 +147,7 @@ echo printf --help echo # CHECK: --help + +# This is how mc likes to encode the directory we should cd to. +printf '%b\n' '\0057foo\0057bar\0057' +# CHECK: /foo/bar/