Skip to content

Commit 75da0b0

Browse files
committed
(#285) Hardens ClientSetup Search Logic
The logic used in the client setup script to search for the latest version of Chocolatey available in the Repository URL had a minor flaw - Using TrimEnd could result in repositories ending in any of the characters in "index" could trim too much. This commit replaces that logic with regex, which hopefully will remove a problem.
1 parent 3caae82 commit 75da0b0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

scripts/ClientSetup.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ if ($Credential) {
8484

8585
# Find the latest version of Chocolatey, if a version was not specified
8686
$NupkgUrl = if (-not $ChocolateyVersion) {
87-
$QueryUrl = ($RepositoryUrl.TrimEnd('/index.json'), "v3/registration/Chocolatey/index.json") -join '/'
87+
$QueryUrl = (($RepositoryUrl -replace '/index\.json$'), "v3/registration/Chocolatey/index.json") -join '/'
8888
$Result = $webClient.DownloadString($QueryUrl) | ConvertFrom-Json
8989
$Result.items.items[-1].packageContent
9090
} else {
9191
# Otherwise, assume the URL
92-
"$($RepositoryUrl.TrimEnd('/index.json'))/v3/content/chocolatey/$($ChocolateyVersion)/chocolatey.$($ChocolateyVersion).nupkg"
92+
"$($RepositoryUrl -replace '/index\.json$')/v3/content/chocolatey/$($ChocolateyVersion)/chocolatey.$($ChocolateyVersion).nupkg"
9393
}
9494

9595
# Download the NUPKG

0 commit comments

Comments
 (0)