Skip to content

Commit bdfa977

Browse files
authored
Merge pull request #111 from microsoft/copilot/fix-aliases-malformed
Fix malformed shell function aliases in artifacts-helper
2 parents 6b84bf5 + c3ece68 commit bdfa977

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎src/artifacts-helper/devcontainer-feature.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Azure Artifacts Credential Helper",
33
"id": "artifacts-helper",
4-
"version": "3.0.7",
4+
"version": "3.0.8",
55
"description": "Configures Codespace to authenticate with Azure Artifact feeds",
66
"options": {
77
"nugetURIPrefixes": {

‎src/artifacts-helper/install.sh‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,19 @@ for ALIAS in "${ALIASES_ARR[@]}"; do
131131
ALIASES_BLOCK+="$ALIAS() { \"${SHIM_DIRECTORY}/$ALIAS\" \"\$@\"; }"$'\n'
132132
done
133133

134+
_TEMP_BLOCK=$(mktemp)
135+
printf '%s' "$ALIASES_BLOCK" > "$_TEMP_BLOCK"
136+
134137
for TARGET_FILE in "${TARGET_FILES_ARR[@]}"; do
135138
if [ "${INSTALL_WITH_SUDO}" = "true" ]; then
136-
sudo -u ${_REMOTE_USER} bash -c "printf '%s' \"$ALIASES_BLOCK\" >> $TARGET_FILE"
139+
sudo -u "${_REMOTE_USER}" bash -c "cat '$_TEMP_BLOCK' >> $TARGET_FILE"
137140
else
138-
printf '%s' "$ALIASES_BLOCK" >> "$TARGET_FILE" || true
141+
cat "$_TEMP_BLOCK" >> "$TARGET_FILE" || true
139142
fi
140143
done
141144

145+
rm -f "$_TEMP_BLOCK"
146+
142147
if [ "${INSTALL_WITH_SUDO}" = "true" ]; then
143148
sudo -u ${_REMOTE_USER} bash -c "/tmp/install-provider.sh ${USENET6}"
144149
fi

‎test/artifacts-helper/test_shim_integration.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ check "npm shell function written to bash.bashrc" grep -q "npm()" /etc/bash.bash
2929
check "dotnet shell function written to bash.bashrc" grep -q "dotnet()" /etc/bash.bashrc
3030
check "npm shell function on its own line in bash.bashrc" grep -q "^npm()" /etc/bash.bashrc
3131

32+
# Verify aliases include proper quoting and argument passing ($@)
33+
check "dotnet alias has quoted path and passes args" grep -q 'dotnet() { ".*/dotnet" "\$@"; }' /etc/bash.bashrc
34+
check "npm alias has quoted path and passes args" grep -q 'npm() { ".*/npm" "\$@"; }' /etc/bash.bashrc
35+
3236
# Verify newlines between shim definitions (each function should be on its own line)
3337
check "each shim function is on its own line" bash -c '
3438
# Count function definitions at line starts - with proper newlines each will start at column 0

0 commit comments

Comments
 (0)