From cc53b058515b094dbc373051bd6be75155fc8f5b Mon Sep 17 00:00:00 2001 From: fengen zhou Date: Thu, 23 Jul 2026 10:13:25 +0800 Subject: [PATCH] fix(git): avoid "illegal byte sequence" in prompt status regex Closes #13330 When `git status --porcelain` output contains an invalid byte sequence (e.g. a filename that is not valid UTF-8 under the current locale), zsh's `=~` regex operator delegates to the C library `regexec`, which aborts with REG_ILLSEQ and prints "regex matching error: illegal byte sequence". This happens once for every status prefix in `_omz_git_prompt_status`, polluting the prompt with repeated error messages and causing all per-file statuses to be lost. Force the C locale inside the function with `local -x LC_ALL=C`. In the C locale every byte is a valid single-byte character, so the regex matching never fails that way. `git status --porcelain` is locale-independent, so the parsed output is unchanged. Verification: `zsh -n lib/git.zsh` passes and the full CI syntax check loop (`zsh -n` on 576 scripts) reports zero failures. --- lib/git.zsh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/git.zsh b/lib/git.zsh index 63482df6e..6d7c2c7dd 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -40,6 +40,15 @@ function _omz_git_prompt_info() { } function _omz_git_prompt_status() { + # OHMYZSH-13330: avoid "regex matching error: illegal byte sequence". + # zsh's "=~" operator delegates to the C library regex, which aborts with + # REG_ILLSEQ when the subject contains an invalid byte sequence under a + # multibyte locale (e.g. a filename with non-UTF-8 bytes in `git status` + # output). Forcing the C locale makes every byte a valid character, so the + # regex matching below never fails that way. `git status --porcelain` is + # locale-independent, so this does not change the parsed output. + local -x LC_ALL=C + [[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return # Maps a git status prefix to an internal constant