zsh-workers
 help / color / Atom feed
* print -v with multibyte characters
@ 2020-02-20 19:03 zsugabubus
  2020-02-20 22:58 ` Mikael Magnusson
  0 siblings, 1 reply; 2+ messages in thread
From: zsugabubus @ 2020-02-20 19:03 UTC (permalink / raw)
  To: zsh-workers

Hi,

  $ echo $ZSH_VERSION
  5.7.1
  $ export {LC_ALL,LANG}=en_US.UTF-8
  $ set -o multibyte && echo ok
  ok

Good:
  $ print ÖÓŐöóő
  ÖÓŐöóő
  $ printf -v var ÖÓŐöóő; echo $var
  ÖÓŐöóő

Bad:
  $ print -v var ÖÓŐ; echo $var
  öó
  $ print -v var öóő; echo $var
  öóŃ

--
zsugabubus

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: print -v with multibyte characters
  2020-02-20 19:03 print -v with multibyte characters zsugabubus
@ 2020-02-20 22:58 ` Mikael Magnusson
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Magnusson @ 2020-02-20 22:58 UTC (permalink / raw)
  To: zsugabubus; +Cc: zsh-workers

On 2/20/20, zsugabubus <zsugabubus@national.shitposting.agency> wrote:
> Hi,
>
>   $ echo $ZSH_VERSION
>   5.7.1
>   $ export {LC_ALL,LANG}=en_US.UTF-8
>   $ set -o multibyte && echo ok
>   ok
>
> Good:
>   $ print ÖÓŐöóő
>   ÖÓŐöóő
>   $ printf -v var ÖÓŐöóő; echo $var
>   ÖÓŐöóő
>
> Bad:
>   $ print -v var ÖÓŐ; echo $var
>   öó
>   $ print -v var öóő; echo $var
>   öóŃ

This gets closer to correct, but seems to leave out the final byte or
two, or change it somehow,
diff --git i/Src/builtin.c w/Src/builtin.c
index 168bf8863b..ed26717b5b 100644
--- i/Src/builtin.c
+++ w/Src/builtin.c
@@ -4848,8 +4848,7 @@ bin_print(char *name, char **args, Options ops, int func)
            if (ret)
                free(buf);
            else
-               setsparam(OPT_ARG(ops, 'v'),
-                         metafy(buf, rcount, META_REALLOC));
+               setsparam(OPT_ARG(ops, 'v'), buf);
            unqueue_signals();
        }
        return ret;
@@ -4972,8 +4971,7 @@ bin_print(char *name, char **args, Options ops, int func)
            if (ret)
                free(buf);
            else
-               setsparam(OPT_ARG(ops, 'v'),
-                         metafy(buf, rcount, META_REALLOC));
+               setsparam(OPT_ARG(ops, 'v'), buf);
            unqueue_signals();
        }
        return ret;

Incidentally you can use print -v var -f %s ÖÓŐ; echo $var to work
around the problem (the handling for -f uses different code which
doesn't have the bug).

-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-20 19:03 print -v with multibyte characters zsugabubus
2020-02-20 22:58 ` Mikael Magnusson

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git