zsh-workers
 help / color / mirror / code / Atom feed
* quoting of bytes >= 0x80 with set +o multibyte in multibyte locales
@ 2024-03-09  9:40 Stephane Chazelas
  0 siblings, 0 replies; only message in thread
From: Stephane Chazelas @ 2024-03-09  9:40 UTC (permalink / raw)
  To: Zsh hackers list

$ locale charmap
UTF-8
$ set +o multibyte
$ a=$'\xe9|\x80'
$ printf '%q\n' $a
�\|$'\200'
$ printf '%s\n' ${(q)a}
�\|$'\200'

Byte 0xe9 was sent as-is to the terminal (which in my case
rendered it as the � replacement character)  even though it's
not printable in UTF-8 (presumably because U+00E9 is printable
but that shouldn't be relevant).

It may get arguably worse in other multibyte charsets. For
example:

$ LC_ALL=zh_HK.big5hkscs luit
$ printf '%s\n' ${(q)a}
ㄍ$'\200'
$ set +o multibyte
$ printf '%s\n' ${(q)a}
α|$'\200'

\xa3\x7c (0x7c being |) is the encoding of U+310D there, while
\xa3\x5c (0x5c being \) is the encoding of U+03B1.

So we ended up with something printable, but only because the \
escaping the | was munched up to form a printable character that
was not there in the input in the first place.

IMO, when the multibyte option is off in a locale with a
multibyte charset, all bytes above 0x7F should be escaped (as
\200..\377).

-- 
Stephane


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-09  9:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-09  9:40 quoting of bytes >= 0x80 with set +o multibyte in multibyte locales Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).