Skip to content

fix: don't crash when list-colors zstyle isn't dircolors-shaped#384

Open
pdehlke wants to merge 1 commit into
romkatv:v5from
pdehlke:v5
Open

fix: don't crash when list-colors zstyle isn't dircolors-shaped#384
pdehlke wants to merge 1 commit into
romkatv:v5from
pdehlke:v5

Conversation

@pdehlke

@pdehlke pdehlke commented Jul 13, 2026

Copy link
Copy Markdown

-z4h-set-list-colors assumed the list-colors style always holds simple GNU dircolors "code=value" pairs. Third-party completion tools (e.g. carapace) can set list-colors themselves using zsh's richer match-highlight syntax (multiple =-separated fields per entry), which splits into an odd number of fields here. Building the associative arrays directly from that odd-length list is a fatal error ("bad set of key/value pairs for associative array") that aborts the whole completion widget, not just this function.

Validate the split lists have even length before building the associative arrays, and bail out (skip colorization for this value) the same way the function already does when no list-colors style is set at all.

-z4h-set-list-colors assumed the list-colors style always holds
simple GNU dircolors "code=value" pairs. Third-party completion
tools (e.g. carapace) can set list-colors themselves using zsh's
richer match-highlight syntax (multiple `=`-separated fields per
entry), which splits into an odd number of fields here. Building
the associative arrays directly from that odd-length list is a
fatal error ("bad set of key/value pairs for associative array")
that aborts the whole completion widget, not just this function.

Validate the split lists have even length before building the
associative arrays, and bail out (skip colorization for this
value) the same way the function already does when no list-colors
style is set at all.
@romkatv

romkatv commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Do you have an example?

Do we need to split only on the first =?

@pdehlke

pdehlke commented Jul 14, 2026

Copy link
Copy Markdown
Author

carapace itself is a little peculiar: the output it emits for a specific invocation depends on how many match-highlight entries carapace emits and how many capture groups each has, which shifts with the match set and even the terminal width. So for example, on MacOS:

❯ echo "ls /Us''" | xargs carapace ls zsh 
=(#b)(Users/)([ ]## -- *)=0=38;2;148;226;213=38;2;127;132;156:=(#b)(Users/)=0=38;2;148;226;213:=(#b)(-- *)=0=38;2;127;132;156

In this particular case the three colon-separated entries happen to add up even, so this exact invocation doesn't cause an abort, but you can see the odd numbered fragment shapes there. Crashing is match-set dependent, not deterministic on every tab completion.

You're much, much smarter about zsh than I am, but here's my thinking about splitting only on the first =:

Splitting on just the first = would stop the crash, but the resulting entry (key = a glob pattern like (#b)(Users/), value = 0=38;2;148;226;213) still couldn't be used — nothing in z4h matches filenames against that pattern. As far as I peronally can tell, it would just trade a crash for a harmless dead entry.

Again as far as I can tell, z4h's colorizer doesn't support pattern-based list-colors entries at all, only literal filename/extension ones. Bailing out when the shape doesn't fit seems like the right thing to do.

@romkatv

romkatv commented Jul 15, 2026

Copy link
Copy Markdown
Owner

If z4h understands only a specific format of this setting, perhaps we should check whether the setting is in that format?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants