Skip to content

Commit

Permalink
_shell_quote: prefer octal.
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
hvdijk committed Apr 12, 2024
1 parent a95a1c2 commit 104c14f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/mystring.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 104c14f

Please sign in to comment.