mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-19 08:01:17 +00:00
fix: replace local -n namerefs in test/record.sh for bash 3.2 compat (#1488)
Why: test/record.sh used local -n (bash 4.3+ namerefs) which crashes on macOS's default bash 3.2, breaking contributor workflow for recording API fixtures. Fixes #1480. Inlines the _export_env_vars_from_fields helper directly into _load_multi_config_from_file, eliminating the nameref dependency while preserving the security validation of env var names. Agent: team-lead Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4d32923d5f
commit
4a6ec4fed7
1 changed files with 12 additions and 22 deletions
|
|
@ -79,27 +79,6 @@ _get_multi_cred_spec() {
|
|||
esac
|
||||
}
|
||||
|
||||
# Extract and export environment variables from loaded data.
|
||||
# Arguments: env_vars_array fields_array
|
||||
# Tab-separated fields are exported to corresponding env vars with security validation.
|
||||
_export_env_vars_from_fields() {
|
||||
local -n env_vars_ref="$1"
|
||||
local -n fields_ref="$2"
|
||||
local i
|
||||
|
||||
for i in "${!env_vars_ref[@]}"; do
|
||||
if [[ -n "${fields_ref[$i]:-}" ]]; then
|
||||
# SECURITY: Validate env var name before export
|
||||
if [[ ! "${env_vars_ref[$i]}" =~ ^[A-Z_][A-Z0-9_]*$ ]]; then
|
||||
echo "SECURITY: Invalid env var name rejected: ${env_vars_ref[$i]}" >&2
|
||||
return 1
|
||||
fi
|
||||
export "${env_vars_ref[$i]}=${fields_ref[$i]}"
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
# Load multiple fields from a JSON config file and export as env vars.
|
||||
# Arguments: CONFIG_FILE SPEC... (each spec is "config_key:ENV_VAR")
|
||||
_load_multi_config_from_file() {
|
||||
|
|
@ -127,7 +106,18 @@ except: pass
|
|||
local IFS=$'\t'
|
||||
local fields
|
||||
read -ra fields <<< "$vals"
|
||||
_export_env_vars_from_fields env_vars fields
|
||||
|
||||
local i
|
||||
for i in "${!env_vars[@]}"; do
|
||||
if [[ -n "${fields[$i]:-}" ]]; then
|
||||
# SECURITY: Validate env var name before export
|
||||
if [[ ! "${env_vars[$i]}" =~ ^[A-Z_][A-Z0-9_]*$ ]]; then
|
||||
echo "SECURITY: Invalid env var name rejected: ${env_vars[$i]}" >&2
|
||||
return 1
|
||||
fi
|
||||
export "${env_vars[$i]}=${fields[$i]}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Save multiple env vars to a JSON config file.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue