Skip to content

Commit 225a065

Browse files
authored
Don't show missing version warning for absoluteLatest (#8199)
Address #8198
1 parent 165984b commit 225a065

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/NuGetGallery/Controllers/PackagesController.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,10 @@ public HttpStatusCodeResult DisplayPackage()
828828
[HttpGet]
829829
public virtual async Task<ActionResult> DisplayPackage(string id, string version)
830830
{
831+
// Attempt to normalize the version but allow version strings that are not actually SemVer strings. For
832+
// example, "absoluteLatest" is allowed as the version string as a reference to the absolute latest version
833+
// including prerelease versions. In this case, the resulting normalized version will be left as the
834+
// original string.
831835
string normalized = NuGetVersionFormatter.Normalize(version);
832836
if (!string.Equals(version, normalized))
833837
{
@@ -890,7 +894,11 @@ public virtual async Task<ActionResult> DisplayPackage(string id, string version
890894
model.GitHubDependenciesInformation = _contentObjectService.GitHubUsageConfiguration.GetPackageInformation(id);
891895
}
892896

893-
if (normalized != null && !string.Equals(package.NormalizedVersion, normalized, StringComparison.OrdinalIgnoreCase))
897+
// If the normalized version is actually a SemVer but does not match the resolved package version, show a
898+
// warning. It's possible that the normalized version is not a SemVer string (like "absoluteLatest").
899+
if (normalized != null
900+
&& !string.Equals(package.NormalizedVersion, normalized, StringComparison.OrdinalIgnoreCase)
901+
&& NuGetVersion.TryParse(normalized, out var parsed))
894902
{
895903
model.VersionRequested = normalized;
896904
model.VersionRequestedWasNotFound = true;

tests/NuGetGallery.Facts/Controllers/PackagesControllerFacts.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ public async Task GivenAnAbsoluteLatestVersionItReturnsTheFirstLatestSemVer2()
896896
// The page should select the first package that is IsLatestSemVer2
897897
Assert.Equal(latestPackage.NormalizedVersion, model.Version);
898898
Assert.True(model.LatestVersionSemVer2);
899+
Assert.False(model.VersionRequestedWasNotFound);
899900

900901
deprecationService.Verify();
901902
}

0 commit comments

Comments
 (0)