Skip to content

Completer scripts broken in PowerShell 7.3+ #1849

Closed
@pinkfloydx33

Description

PowerShell 7.3 has corrected a long-standing bug with quote escaping during native argument passing. This causes existing quoting work-arounds to break. In it's current form, the completer scripts no longer work in PowerShell 7.3+ when using the new default settings and attempting to complete an empty command (ie. command [tab] vs command s[tab]).

The offending lines:

`+" # We need to use `\"`\" to pass an empty argument a \"\" or '' does not work!!!"+`
`+" $RequestComp=\"$RequestComp\" + ' `\"`\"'"+`

It's sort of hard to see, but the single back ticks escaping the quotes near the end of line 110 need to be removed. However it's dependent on both the version of PowerShell and the new preference variable for native command arguments, $PSNativeCommandArgumentPassing, so a better fix is likely the following (note this is in PowerShell, not as an embedded go string) :

# We need to use `"`" to pass an empty argument a "" or '' does not work!!!
# PowerShell 7.3+ need to use "" if Argument Passing is not Legacy	
if ($PSVersionTable.PsVersion -lt [version]'7.3.0' -or $PSNativeCommandArgumentPassing -eq 'Legacy') {
     $RequestComp="$RequestComp" + ' `"`"'
} else {
     $RequestComp="$RequestComp" + ' ""'
}

I'm not sure if that's the most elegant fix nor if it is 100% correct given that there's multiple modes (Legacy, Standard and Windows). I'm also not sure if the script needs any other modifications, though in my limited testing it is has fixed all of the completer scripts I use that were generated via this library (ie. flux/helm/kustomize)

See GitHub issues here and here as well as documentation for PSNativeCommandArgumentPassing (which despite being on the experimental features page is actually mainstream/GA in 7.3)

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions