bin/brew: tighten check in export_homebrew_env_file

The current glob check will accept lines like

  HOMEBREW_FOO=bar BAD_ENV_VAR=baz

and happily export them, but we don't want that.

Let's tighten up the check to reject lines like the above.
This commit is contained in:
Carlo Cabrera 2024-08-20 14:48:43 +08:00
parent f82945ffa0
commit 4a11e74307
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -108,14 +108,14 @@ HOMEBREW_LIBRARY="${HOMEBREW_REPOSITORY}/Library"
# Load Homebrew's variable configuration files from disk.
export_homebrew_env_file() {
local env_file
local env_file="${1}"
local homebrew_env_regex="^HOMEBREW_[A-Z_]+=[^=]*$"
env_file="${1}"
[[ -r "${env_file}" ]] || return 0
while read -r line
do
# only load HOMEBREW_* lines
[[ "${line}" = "HOMEBREW_"* ]] || continue
[[ "${line}" =~ ${homebrew_env_regex} ]] || continue
export "${line?}"
done <"${env_file}"
}