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

[PATCH] zstat: double metafy fix



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, ")");
     }



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