Fix V3 packageContent URL selection to compare parsed versions - #2019
Open
Eugene Tolmachev (et1975) wants to merge 2 commits into
Open
Fix V3 packageContent URL selection to compare parsed versions#2019Eugene Tolmachev (et1975) wants to merge 2 commits into
Eugene Tolmachev (et1975) wants to merge 2 commits into
Conversation
… 1657) Co-authored-by: et1975 <623703+et1975@users.noreply.github.com>
Eugene Tolmachev (et1975)
requested review from
Aditya Patwardhan (adityapatwardhan),
alerickson and
Anam Navied (anamnavi)
as code owners
August 19, 2026 15:31
Eugene Tolmachev (et1975)
requested review from
Sydney Smith (SydneyhSmith) and
shammu1
as code owners
August 19, 2026 15:31
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Fixes incorrect V3 .nupkg selection during Install/Save by replacing substring-based URL matching with parsed NuGetVersion comparisons, preventing version-prefix collisions (e.g., 1.2.3 vs 1.2.30) that can download the wrong payload into the requested version folder.
Changes:
- Replaced substring URL matching in V3 install paths with a new helper that extracts and compares parsed versions.
- Added a
TestHooksentry point so URL selection can be unit-tested without a live feed. - Added Pester coverage for prefix-collision versions, 4-part versions, prereleases, query-parameter URLs, and the not-found case.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/code/V3ServerAPICalls.cs | Introduces version-parsing URL matcher and uses it in sync/async install paths. |
| src/code/PSResourceInfo.cs | Adds TestHooks.SelectV3PackageContentUrl to expose selection logic for tests. |
| test/InstallPSResourceTests/InstallPSResourceV3ServerVersionSelection.Tests.ps1 | Adds tests covering exact-match selection across several URL/version shapes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…election Co-authored-by: et1975 <623703+et1975@users.noreply.github.com>
Lara Bailen Boluda (larabail)
approved these changes
Aug 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Install-PSResource/Save-PSResource against a V3 feed can download the payload of a different version than requested while writing it under the requested version's folder. The V3 download path picked the packageContent URL by substring match, so a requested version that is a text prefix of another version matched the wrong entry.
V3ServerAPICalls.InstallHelper and InstallHelperAsync did:
Requesting 1.2.3 matches .../test_module/1.2.30/test_module.1.2.30.nupkg first. This also explains why exact-range syntax ([1.2.3]) doesn't help: by this point the spec is already a parsed NuGetVersion, and only the final URL selection is text-based. FindVersionHelper already compares parsed versions, which is why Find reports the right version while the downloaded content is wrong.
Closes #1657
Changes
src/code/V3ServerAPICalls.cs — new GetPackageContentUrlForVersion helper that extracts the version from a packageContent entry and compares it as a NuGetVersion. Recognized shapes: version path segment (.../{name}/{version}/...), .{version}.nupkg file name suffix, and version-bearing query parameters (e.g. MyGet-style ?packageVersion=). Both the sync and async install paths now use it.
src/code/PSResourceInfo.cs — TestHooks.SelectV3PackageContentUrl entry point, following the existing TestHooks pattern, so URL selection is testable without a live feed.
test/InstallPSResourceTests/InstallPSResourceV3ServerVersionSelection.Tests.ps1 — covers 1.2.3 vs 1.2.30, the reported 2024.5.20.1 vs 2024.5.20.12, prereleases (2.5.0-beta1 vs 2.5.0-beta10), query-parameter URLs, and the not-found case. The prefix cases fail against the previous substring logic.
Behavioral note
Entries whose version can't be recovered from the URL are no longer matched at all, rather than being matched on any incidental substring occurrence. Non-matching now surfaces the existing "could not be found in repository" error instead of silently downloading a neighboring version.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.