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

[PATCH] Fix rendering bug in completion formatter

Found a tiny Christmas bug~

The completion formatting code is meant to support the same colour sequences
with %F and %K as in prompt expansion: either in the simple numeric format like
%1F or in the extended format like %F{1} or %F{red}. An error on the completion
side prevents the simple numeric format from working at all, and has the
side-effect of swallowing up any numbers that follow other sequences like %B.


  % zsh -f
  % autoload -Uz compinit && compinit
  % zstyle ':completion:*' group-name ''
  % zstyle ':completion:*:descriptions' format '%5F123abc%f %5K123abc%k %B123abc%b'
  % tr -<TAB>

  F123abc K123abc abc
  123abc 123abc 123abc

There is similar code in zle_tricky.c but it doesn't look like it suffers from
the same issue (i don't actually know how to test it though).

Not sure a regression test is super necessary but i've included that too.


diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index a83daeff9..e768aee5d 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -1096,18 +1096,18 @@ compprintfmt(char *fmt, int n, int dopr, int doesc, int ml, int *stop)
 	    p += len;
 	    if (*p) {
 		int arg = 0, is_fg;
+		if (idigit(*p))
+		    arg = zstrtol(p, &p, 10);
 		len = MB_METACHARLENCONV(p, &cchar);
 		if (cchar == WEOF)
 		    cchar = (wchar_t)(*p == Meta ? p[1] ^ 32 : *p);
 		p += len;
-		if (idigit(*p))
-		    arg = zstrtol(p, &p, 10);
 		m = 0;
 		switch (cchar) {
 		case ZWC('%'):
 		    if (dopr == 1)

diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index 113a45076..b1c0e40e5 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -56,6 +56,21 @@
+  # Temporarily modify format set in comptest
+  comptesteval 'zstyle -s ":completion:*:descriptions" format oldfmt'
+  comptesteval 'zstyle ":completion:*:descriptions" format \
+    ${oldfmt/>*</>%5F123abc%f %B123abc%b<}'
+  comptest $': \t'
+  comptesteval 'zstyle ":completion:*:descriptions" format $oldfmt'
+0:custom description with formatting sequences
+>line: {: }{}
+F:regression test workers/42164
 # Depends on path assignment in comptestinit
   comptesteval "path=( $ZTST_srcdir:A )"
   comptest $'zt\t'

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