Skip to content

Commit 15a88af

Browse files
committed
chocolateyGH-405: fix edge case Get-PackageNamesFromInvocationLine
1 parent 7cfa0ee commit 15a88af

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Boxstarter.Chocolatey/Chocolatey.ps1

+4-1
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,13 @@ function Get-PackageNamesFromInvocationLine {
364364
if ($namedParameters -contains $param) {
365365
$skipNext = $true
366366
}
367-
elseif ($param -contains '=') {
367+
elseif ($param.IndexOf('=') -eq $param.Length - 1) {
368368
$skipNext = $true
369369
}
370370
}
371+
elseif ($a -eq '=') {
372+
$skipNext = $true
373+
}
371374
else {
372375
$packageNames += $a
373376
}

tests/Chocolatey/Chocolatey.tests.ps1

+12
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,18 @@ Describe "Get-PackageNamesFromInvocationLine" {
479479
$pkgNames = Get-PackageNamesFromInvocationLine @("-foo=bar", "pkg1", "-pkg2=???")
480480
$pkgNames | Should Be "pkg1"
481481
}
482+
It "ignores any parameter that contains a '=' (weird case)" {
483+
$pkgNames = Get-PackageNamesFromInvocationLine @("-foo", "=", "bar", "pkg1", "-pkg2=???")
484+
$pkgNames | Should Be "pkg1"
485+
}
486+
It "ignores any parameter that contains a '=' (paranoid case)" {
487+
$pkgNames = Get-PackageNamesFromInvocationLine @("-a=", "paranoid", "-foo", "=", "bar", "pkg1", "-pkg2=???")
488+
$pkgNames | Should Be @("pkg1")
489+
}
490+
It "ignores any parameter that contains a '=' (paranoid case x paranoid case)" {
491+
$pkgNames = Get-PackageNamesFromInvocationLine @("-a=", "paranoid", "-foo", "=", "bar", @("-a=paranoid"), "pkg1", @("-a", "=", "paranoid"), "-pkg2=???")
492+
$pkgNames | Should Be @("pkg1")
493+
}
482494
}
483495

484496
Describe "Install-ChocolateyInstallPackageOverride" {

0 commit comments

Comments
 (0)