898b579cf51026e95f0249f57e36387227e7a184

Author
zhoufengen <135676703+zhoufengen@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

fix(git): avoid illegal byte sequence (#13878)

Diff

 1diff --git a/lib/git.zsh b/lib/git.zsh
 2index 63482df6e07c03ca19d6c6882e6bef73927cd3a6..6d7c2c7ddcf9d86a5685935fd9b3a583a639aa67 100644
 3--- a/lib/git.zsh
 4+++ b/lib/git.zsh
 5@@ -40,6 +40,15 @@ function _omz_git_prompt_info() {
 6 }
 7 
 8 function _omz_git_prompt_status() {
 9+  # OHMYZSH-13330: avoid "regex matching error: illegal byte sequence".
10+  # zsh's "=~" operator delegates to the C library regex, which aborts with
11+  # REG_ILLSEQ when the subject contains an invalid byte sequence under a
12+  # multibyte locale (e.g. a filename with non-UTF-8 bytes in `git status`
13+  # output). Forcing the C locale makes every byte a valid character, so the
14+  # regex matching below never fails that way. `git status --porcelain` is
15+  # locale-independent, so this does not change the parsed output.
16+  local -x LC_ALL=C
17+
18   [[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return
19 
20   # Maps a git status prefix to an internal constant