diff --git a/bin/gstack-gbrain-lib.sh b/bin/gstack-gbrain-lib.sh index 7498e568d5..b89cce2e03 100644 --- a/bin/gstack-gbrain-lib.sh +++ b/bin/gstack-gbrain-lib.sh @@ -27,8 +27,22 @@ # restore), D16 (pooler URL paste hygiene with redacted preview). # _gstack_gbrain_validate_varname — returns 0 if usable, 2 otherwise. +# `local LC_ALL=C` is load-bearing twice over: +# 1. In many macOS shells the default locale (e.g. en_US.UTF-8) makes `case` +# glob brackets like `[A-Z]` match lowercase letters too. Without the +# LC_ALL=C pin, names like `lower-case` pass validation and then trip +# `printf -v "$varname"` and `export "$varname"` with "not a valid +# identifier" errors the caller can't easily distinguish from other +# failures. +# 2. `local` is required because this file is documented as a sourced helper +# (see header), so a bare `LC_ALL=C` would mutate the caller's locale for +# the rest of the process — silently affecting downstream `sort`, `tr`, +# and any locale-aware glob in the same shell. +# Together they give ASCII-only bracket semantics on both macOS and Linux +# (matching the documented `[A-Z_][A-Z0-9_]*` contract) without leaking. _gstack_gbrain_validate_varname() { local name="$1" + local LC_ALL=C case "$name" in [A-Z_][A-Z0-9_]*) return 0 ;; *) return 2 ;;