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

Re: [BUG] E02 test failure / ztst *> issue



> 2020/03/12 6:15, dana <dana@xxxxxxx> wrote:
> 
> When i run E02 on master, on macOS, i get an failure for the new 'preserves
> tracing' test (see output below). On my machine, `which` outputs the name of
> the ヌ function without quoting.

I noticed this on macOS few days ago or so, and was testing on other BSDs,
and yes, the test fails (at least) on Free/Net/Open BSDs. It turned out
that the problem is in zsh itself; a patch is at the end of this post.


The test is run under C-locale, but on BSDs "which" outputs the function
name ヌ (utdf-8: e3 83 8c) as raw bytes instead of escaping by \M and \C.
On Linux the test succeeds.

The function name is printed by quotedzputs(), which calls
is_mb_niceformat(), and mbrtowc() (line 5422, utils.c). Under C locale,
mbrtowc() behaves differently on Linux and BSDs.

On Linux, mbrtowc(&c, 0xe3;0x83;0x8c, ..) returns MB_INVALID if called
under C locale. So the 1st byte 0xe3 is an invalid byte.

On BSDs it returns 1, indicating that 0xe3 is a valid single byte
character (but not printable because isprint(0xe3) is 0).

But this should not make any difference, because zsh is *expected* to
print either invalid or unprintable byte by escaping with \M- and \C-
(by using one of nicechar-family functions).

The real problem is in is_wcs_nicechar() that is called from
is_mb_niceformat() (line 5452, utils.c); is_mb_niceformat(0xe3)
should return 1 but actually returns 0. The 2nd hunk in the path below
fixes this. But only with this hunk, the function name is output as
$'\M-c\M-^C\M-^L'
i.e., ^X instead of \C-X. The first hunk in the patch fixes this.



diff --git a/Src/utils.c b/Src/utils.c
index f9c2d4a2b..5ffc459f2 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -711,7 +711,7 @@ wcs_nicechar_sel(wchar_t c, size_t *widthp, char **swidep, int quotable)
 	    if (widthp)
 		*widthp = 6;
 	} else {
-	    strcpy(buf, nicechar((int)c));
+	    strcpy(buf, nicechar_sel((int)c, quotable));
 	    /*
 	     * There may be metafied characters from nicechar(),
 	     * so compute width and end position independently.
@@ -771,7 +771,7 @@ mod_export int is_wcs_nicechar(wchar_t c)
 	if (c == 0x7f || c == L'\n' || c == L'\t' || c < 0x20)
 	    return 1;
 	if (c >= 0x80) {
-	    return (c >= 0x100);
+	    return (c >= 0x100 || is_nicechar(c));
 	}
     }
     return 0;






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