Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support : in values for VSCODE_ENV_* variables #182781

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if [ -n "$VSCODE_ENV_REPLACE" ]; then
IFS=':' read -ra ADDR <<< "$VSCODE_ENV_REPLACE"
for ITEM in "${ADDR[@]}"; do
VARNAME="$(echo $ITEM | cut -d "=" -f 1)"
VALUE="$(echo $ITEM | cut -d "=" -f 2)"
VALUE="$(echo -e "$ITEM" | cut -d "=" -f 2)"
export $VARNAME="$VALUE"
done
builtin unset VSCODE_ENV_REPLACE
Expand All @@ -59,7 +59,7 @@ if [ -n "$VSCODE_ENV_PREPEND" ]; then
IFS=':' read -ra ADDR <<< "$VSCODE_ENV_PREPEND"
for ITEM in "${ADDR[@]}"; do
VARNAME="$(echo $ITEM | cut -d "=" -f 1)"
VALUE="$(echo $ITEM | cut -d "=" -f 2)"
VALUE="$(echo -e "$ITEM" | cut -d "=" -f 2)"
export $VARNAME="$VALUE${!VARNAME}"
done
builtin unset VSCODE_ENV_PREPEND
Expand All @@ -68,7 +68,7 @@ if [ -n "$VSCODE_ENV_APPEND" ]; then
IFS=':' read -ra ADDR <<< "$VSCODE_ENV_APPEND"
for ITEM in "${ADDR[@]}"; do
VARNAME="$(echo $ITEM | cut -d "=" -f 1)"
VALUE="$(echo $ITEM | cut -d "=" -f 2)"
VALUE="$(echo -e "$ITEM" | cut -d "=" -f 2)"
export $VARNAME="${!VARNAME}$VALUE"
done
builtin unset VSCODE_ENV_APPEND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,26 @@ fi

# Apply EnvironmentVariableCollections if needed
if [ -n "$VSCODE_ENV_REPLACE" ]; then
echo "VSCODE_ENV_REPLACE: $VSCODE_ENV_REPLACE"
IFS=':' read -rA ADDR <<< "$VSCODE_ENV_REPLACE"
for ITEM in "${ADDR[@]}"; do
VARNAME="$(echo ${ITEM%%=*})"
export $VARNAME="${ITEM#*=}"
export $VARNAME="$(echo -e ${ITEM#*=})"
done
unset VSCODE_ENV_REPLACE
fi
if [ -n "$VSCODE_ENV_PREPEND" ]; then
echo "VSCODE_ENV_PREPEND: $VSCODE_ENV_PREPEND"
IFS=':' read -rA ADDR <<< "$VSCODE_ENV_PREPEND"
for ITEM in "${ADDR[@]}"; do
VARNAME="$(echo ${ITEM%%=*})"
export $VARNAME="${ITEM#*=}${(P)VARNAME}"
export $VARNAME="$(echo -e {ITEM#*=})${(P)VARNAME}"
done
unset VSCODE_ENV_PREPEND
fi
if [ -n "$VSCODE_ENV_APPEND" ]; then
echo "VSCODE_ENV_APPEND: $VSCODE_ENV_APPEND"
IFS=':' read -rA ADDR <<< "$VSCODE_ENV_APPEND"
for ITEM in "${ADDR[@]}"; do
VARNAME="$(echo ${ITEM%%=*})"
export $VARNAME="${(P)VARNAME}${ITEM#*=}"
export $VARNAME="${(P)VARNAME}$(echo -e {ITEM#*=})"
done
unset VSCODE_ENV_APPEND
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ if test -n "$VSCODE_ENV_REPLACE"
set ITEMS (string split : $VSCODE_ENV_REPLACE)
for B in $ITEMS
set split (string split = $B)
set -gx "$split[1]" "$split[2]"
set -gx "$split[1]" (echo -e "$split[2]")
end
set -e VSCODE_ENV_REPLACE
end
if test -n "$VSCODE_ENV_PREPEND"
set ITEMS (string split : $VSCODE_ENV_PREPEND)
for B in $ITEMS
set split (string split = $B)
set -gx "$split[1]" "$split[2]$$split[1]" # avoid -p as it adds a space
set -gx "$split[1]" (echo -e "$split[2]")"$$split[1]" # avoid -p as it adds a space
end
set -e VSCODE_ENV_PREPEND
end
if test -n "$VSCODE_ENV_APPEND"
set ITEMS (string split : $VSCODE_ENV_APPEND)
for B in $ITEMS
set split (string split = $B)
set -gx "$split[1]" "$$split[1]$split[2]" # avoid -a as it adds a space
set -gx "$split[1]" "$$split[1]"(echo -e "$split[2]") # avoid -a as it adds a space
end
set -e VSCODE_ENV_APPEND
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ if ($env:VSCODE_ENV_REPLACE) {
$Split = $env:VSCODE_ENV_REPLACE.Split(":")
foreach ($Item in $Split) {
$Inner = $Item.Split('=')
[Environment]::SetEnvironmentVariable($Inner[0], $Inner[1])
[Environment]::SetEnvironmentVariable($Inner[0], $Inner[1].Replace('\x3a', ':'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what this does?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When vscode sets the variable it will ensure all values have : encoded as \x3a', so to test this out you'll want to encode the values like this:

VAR1=VAL1:VAR2=http\x3a//github.com

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do it this way because we can't pass \0 into environment variables and splitting multi-character strings is tricky in some shells.

}
$env:VSCODE_ENV_REPLACE = $null
}
if ($env:VSCODE_ENV_PREPEND) {
$Split = $env:VSCODE_ENV_PREPEND.Split(":")
foreach ($Item in $Split) {
$Inner = $Item.Split('=')
[Environment]::SetEnvironmentVariable($Inner[0], $Inner[1] + [Environment]::GetEnvironmentVariable($Inner[0]))
[Environment]::SetEnvironmentVariable($Inner[0], $Inner[1].Replace('\x3a', ':') + [Environment]::GetEnvironmentVariable($Inner[0]))
}
$env:VSCODE_ENV_PREPEND = $null
}
if ($env:VSCODE_ENV_APPEND) {
$Split = $env:VSCODE_ENV_APPEND.Split(":")
foreach ($Item in $Split) {
$Inner = $Item.Split('=')
[Environment]::SetEnvironmentVariable($Inner[0], [Environment]::GetEnvironmentVariable($Inner[0]) + $Inner[1])
[Environment]::SetEnvironmentVariable($Inner[0], [Environment]::GetEnvironmentVariable($Inner[0]) + $Inner[1].Replace('\x3a', ':'))
}
$env:VSCODE_ENV_APPEND = $null
}
Expand Down