zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: quoting of bytes >= 0x80 with set +o multibyte in multibyte locales
Date: Sat, 9 Mar 2024 09:40:19 +0000	[thread overview]
Message-ID: <20240309094019.w524x42frygvqmxd@chazelas.org> (raw)

$ 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


                 reply	other threads:[~2024-03-09  9:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240309094019.w524x42frygvqmxd@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).