zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] zstat: double metafy fix
@ 2018-11-14  4:07 ivan tkachenko
  2018-11-15  1:47 ` Jun T
  0 siblings, 1 reply; 2+ messages in thread
From: ivan tkachenko @ 2018-11-14  4:07 UTC (permalink / raw)
  To: zsh-workers

Hello, zsh team!

I've found and successfully fixed a bug of double escaping formatted time in
`zstat` builtin with the patch below. This bug only affects locales (or rather
languages) other than english and only in some corner cases when characters'
codepoints collide with zsh's "Meta" definition, however it was still pretty
annoying, for example, for russian locale (ru_RU.UTF-8).

Relevant issue in irrelevant repository on GitHub:
https://github.com/supercrabtree/k/pull/87

I would also like to add tests for '%b' time formatting, but not sure which way
to go, because such test requires some OS setup.

For dockerized Debian:jessie steps to reproduce are as follow:

1) Build image from the following Dockerfile

    % docker build -t zsh . -f- <<EOF

    FROM buildpack-deps:jessie

    RUN apt-get update && apt-get install -y --no-install-recommends \
            locales \
        && rm -rf /var/lib/apt/lists/*

    RUN echo "ru_RU.UTF-8 UTF-8" >> /etc/locale.gen \
        && locale-gen \
        && update-locale

    ENV LANG=ru_RU.UTF-8

    # zsh repository is assumed to be in the current directory
    ADD . /src
    WORKDIR /src

    RUN ./Util/preconfig
    # tons of options blindly copied from Arch Linux PKGBUILD for zsh
    # https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/zsh
    RUN ./configure --prefix=/usr \
        --docdir=/usr/share/doc/zsh \
        --htmldir=/usr/share/doc/zsh/html \
        --enable-etcdir=/etc/zsh \
        --enable-zshenv=/etc/zsh/zshenv \
        --enable-zlogin=/etc/zsh/zlogin \
        --enable-zlogout=/etc/zsh/zlogout \
        --enable-zprofile=/etc/zsh/zprofile \
        --enable-zshrc=/etc/zsh/zshrc \
        --enable-maildir-support \
        --with-term-lib='ncursesw' \
        --enable-multibyte \
        --enable-function-subdirs \
        --enable-fndir=/usr/share/zsh/functions \
        --enable-scriptdir=/usr/share/zsh/scripts \
        --with-tcsetpgrp \
        --enable-pcre \
        --enable-cap \
        --enable-zsh-secure-free
    RUN make && make install.bin install.modules

    CMD zsh

    EOF

2) Run inside the container the following command

    % zmodload zsh/stat && zstat -F '%b' .

3) See something like

    atime   ноу�
    mtime   сен


All the best!

diff --git a/Src/Modules/stat.c b/Src/Modules/stat.c
index 50a6a9bb2..ed75ea691 100644
--- a/Src/Modules/stat.c
+++ b/Src/Modules/stat.c
@@ -200,8 +200,6 @@ stattimeprint(time_t tim, long nsecs, char *outbuf, int flags)
        /* Where the heck does "40" come from? */
        int len = ztrftime(oend, 40, timefmt, (flags & STF_GMT) ? gmtime(&tim) :
                           localtime(&tim), nsecs);
-       if (len > 0)
-           metafy(oend, len, META_NOALLOC);
        if (flags & STF_RAW)
            strcat(oend, ")");
     }

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

* Re: [PATCH] zstat: double metafy fix
  2018-11-14  4:07 [PATCH] zstat: double metafy fix ivan tkachenko
@ 2018-11-15  1:47 ` Jun T
  0 siblings, 0 replies; 2+ messages in thread
From: Jun T @ 2018-11-15  1:47 UTC (permalink / raw)
  To: ivan tkachenko, zsh-workers


> 2018/11/14 13:0, ivan tkachenko <me@ratijas.tk> wrote:
> 
> I've found and successfully fixed a bug of double escaping formatted time in
> `zstat` builtin with the patch below. 

Thanks, and Yes, the metafy() there should be removed.

#the string need be metafy()ed only for 'zstat -A array_name'
 
I will push the following (i.e., remove the unused variable 'len')

Jun


diff --git a/Src/Modules/stat.c b/Src/Modules/stat.c
index 50a6a9bb2..7c736072b 100644
--- a/Src/Modules/stat.c
+++ b/Src/Modules/stat.c
@@ -198,10 +198,8 @@ stattimeprint(time_t tim, long nsecs, char *outbuf, int flags)
     if (flags & STF_STRING) {
 	char *oend = outbuf + strlen(outbuf);
 	/* Where the heck does "40" come from? */
-	int len = ztrftime(oend, 40, timefmt, (flags & STF_GMT) ? gmtime(&tim) :
+	ztrftime(oend, 40, timefmt, (flags & STF_GMT) ? gmtime(&tim) :
 			   localtime(&tim), nsecs);
-	if (len > 0)
-	    metafy(oend, len, META_NOALLOC);
 	if (flags & STF_RAW)
 	    strcat(oend, ")");
     }




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

end of thread, other threads:[~2018-11-15  2:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14  4:07 [PATCH] zstat: double metafy fix ivan tkachenko
2018-11-15  1:47 ` Jun T

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).