From 104c14f30b09aeeb80021bf519b343379e511e0d Mon Sep 17 00:00:00 2001 From: Harald van Dijk Date: Fri, 12 Apr 2024 01:37:53 +0100 Subject: [PATCH] _shell_quote: prefer octal. If we are in a single-byte locale and encounter a non-printable character we need to escape, previously, if the byte formed a valid Unicode character, we would print it using \uXXXX notation. For single-byte characters, use the more compact \XXX octal notation instead. Test case: LC_ALL=en_US.ISO-8859-1 $SHELL -xc $': \237' --- src/mystring.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mystring.c b/src/mystring.c index 6fcb07d..7f584a0 100644 --- a/src/mystring.c +++ b/src/mystring.c @@ -336,8 +336,10 @@ shell_quote(const char *s, int style) } /* } */ #ifdef WITH_LOCALE if (!iswprint(c) || (c != ' ' && iswblank(c))) { - if (c < 128) + if (q - p == 1) { + c = (unsigned char) *p; goto oct; + } fmt = c >= 0x10000 ? "\\U%08x" : "\\u%04x"; goto fmt; }