mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-08-07 06:08:39 +02:00
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.
This commit is contained in:
parent
e1d1f0dcd5
commit
cc53b05851
1 changed files with 9 additions and 0 deletions
|
|
@ -40,6 +40,15 @@ function _omz_git_prompt_info() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omz_git_prompt_status() {
|
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
|
[[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return
|
||||||
|
|
||||||
# Maps a git status prefix to an internal constant
|
# Maps a git status prefix to an internal constant
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue