Skip to content

Commit 567ea8e

Browse files
oldiumOldřich Jedlička
and
Oldřich Jedlička
authored
Add support for PowerShell 7.2+ (#1916)
PowerShell 7.2 has changed the way arguments are passed to executables. This was originally an experimental feature in 7.2, but as of 7.3 it is built-in. A simple "" is now sufficient for passing empty arguments, no back-tick escaping is required. Fixes #1849 Signed-off-by: Oldřich Jedlička <[email protected]> Co-authored-by: Oldřich Jedlička <[email protected]>
1 parent 3daa4b9 commit 567ea8e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

powershell_completions.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,17 @@ filter __%[1]s_escapeStringWithSpecialChars {
107107
# If the last parameter is complete (there is a space following it)
108108
# We add an extra empty parameter so we can indicate this to the go method.
109109
__%[1]s_debug "Adding extra empty parameter"
110-
`+" # We need to use `\"`\" to pass an empty argument a \"\" or '' does not work!!!"+`
111-
`+" $RequestComp=\"$RequestComp\" + ' `\"`\"'"+`
110+
# PowerShell 7.2+ changed the way how the arguments are passed to executables,
111+
# so for pre-7.2 or when Legacy argument passing is enabled we need to use
112+
`+" # `\"`\" to pass an empty argument, a \"\" or '' does not work!!!"+`
113+
if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
114+
($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or
115+
(($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and
116+
$PSNativeCommandArgumentPassing -eq 'Legacy')) {
117+
`+" $RequestComp=\"$RequestComp\" + ' `\"`\"'"+`
118+
} else {
119+
$RequestComp="$RequestComp" + ' ""'
120+
}
112121
}
113122
114123
__%[1]s_debug "Calling $RequestComp"

0 commit comments

Comments
 (0)