Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

quoting of bytes >= 0x80 with set +o multibyte in multibyte locales



$ 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




Messages sorted by: Reverse Date, Date, Thread, Author