Skip to content

Commit

Permalink
Properly escape special characters & quote arguments
Browse files Browse the repository at this point in the history
Note:

- Passing arguments to mingw/cygwin bash does not work without `bash -c`
- Not much I can do for PowerShell: https://github.com/Azure/azure-cli/blob/dev/doc/quoting-issues-with-powershell.md
  • Loading branch information
sitiom committed Aug 20, 2024
1 parent e182062 commit 3daf211
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1003,14 +1003,18 @@ function shim($path, $global, $name, $arg) {
) -join "`n" | Out-UTF8File $shim -NoNewLine
} else {
warn_on_overwrite "$shim.cmd" $path
$quoted_arg = if ($arg.Count -gt 0) { $arg | ForEach-Object { "`"$_`"" } }
@(
"@rem $resolved_path",
'@echo off',
'bash -c "command -v wslpath >/dev/null"',
'if %errorlevel% equ 0 (',
" bash `"`$(wslpath -u '$resolved_path')`" $arg %*",
" bash `"`$(wslpath -u '$resolved_path')`" $quoted_arg %*",
') else (',
" bash `"`$(cygpath -u '$resolved_path')`" $arg %*",
" set args=$quoted_arg %*",
' setlocal enabledelayedexpansion',
' if not "!args!"=="" set args=!args:"=""!',
" bash -c `"`$(cygpath -u '$resolved_path') !args!`"",
')'
) -join "`r`n" | Out-UTF8File "$shim.cmd"

Expand Down

0 comments on commit 3daf211

Please sign in to comment.