mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-04-10 04:26:17 +02:00
fix(git-lib): avoid regex error with non-ASCII branch names
_omz_git_prompt_status was emitting "regex matching error: illegal byte sequence" when the git branch name contained non-ASCII characters (e.g. Chinese). The zsh =~ operator uses locale-aware POSIX ERE, so character classes like [^ ]+ reject multibyte sequences unless LC_ALL=C is set. Fix by setting LC_ALL=C around all regex operations in the function and restoring it afterwards. Fixes #13330
This commit is contained in:
parent
887a864aba
commit
1d04379d4f
2 changed files with 81 additions and 0 deletions
|
|
@ -103,6 +103,11 @@ function _omz_git_prompt_status() {
|
|||
local status_lines
|
||||
status_lines=("${(@f)${status_text}}")
|
||||
|
||||
# Use C locale for regex matching to avoid "illegal byte sequence" errors
|
||||
# when branch names or file paths contain non-ASCII characters (e.g. Chinese)
|
||||
local _omz_lc_all=$LC_ALL
|
||||
LC_ALL=C
|
||||
|
||||
# If the tracking line exists, get and parse it
|
||||
if [[ "$status_lines[1]" =~ "^## [^ ]+ \[(.*)\]" ]]; then
|
||||
local branch_statuses
|
||||
|
|
@ -126,6 +131,8 @@ function _omz_git_prompt_status() {
|
|||
fi
|
||||
done
|
||||
|
||||
LC_ALL=$_omz_lc_all
|
||||
|
||||
# Display the seen statuses in the order specified
|
||||
local status_prompt
|
||||
for status_constant in $status_constants; do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue