mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-29 04:53:17 +02:00
fix(dotenv): add support for escaped dollars
This commit is contained in:
parent
785db2faa3
commit
d30724763f
2 changed files with 29 additions and 3 deletions
|
|
@ -143,11 +143,9 @@ _parse_dotenv_content() {
|
|||
fi
|
||||
## END: FILTER COMMAND EXPANSION
|
||||
|
||||
# Unquote the value to handle special characters and multiline values
|
||||
value="${(Q)value}"
|
||||
|
||||
# Single-quoted values are fully literal and must not participate in expansion.
|
||||
if [[ "$raw_value" == \'*\' ]]; then
|
||||
value="${(Q)value}"
|
||||
parsed_vars[$key]="$value"
|
||||
if [[ "$mode" == "export" ]]; then
|
||||
typeset -x "$key"="$value"
|
||||
|
|
@ -155,6 +153,13 @@ _parse_dotenv_content() {
|
|||
continue
|
||||
fi
|
||||
|
||||
# Preserve escaped dollars so they remain literal after unquoting.
|
||||
local escaped_dollar_placeholder=$'\001DOTENV_ESCAPED_DOLLAR\001'
|
||||
value="${value//\\\$/$escaped_dollar_placeholder}"
|
||||
|
||||
# Unquote the value to handle special characters and multiline values.
|
||||
value="${(Q)value}"
|
||||
|
||||
# Expand previously parsed in-file variables without partial name matches.
|
||||
local expanded="" prefix remainder="$value" var_name
|
||||
while [[ "$remainder" == *'$'* ]]; do
|
||||
|
|
@ -179,6 +184,7 @@ _parse_dotenv_content() {
|
|||
fi
|
||||
done
|
||||
value="${expanded}${remainder}"
|
||||
value="${value//$escaped_dollar_placeholder/\$}"
|
||||
|
||||
# Store in parsed vars (for in-file expansion)
|
||||
parsed_vars[$key]="$value"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue