From 62275514c0e953213c1d3e9ca312fec5c5e76e8a Mon Sep 17 00:00:00 2001 From: Daniel Jacinto Date: Thu, 20 Apr 2023 21:13:30 -0700 Subject: [PATCH] AdvisoryUrl, and AlternatePackage fix. --- .../Helpers/SearchResponseHelper.cs | 24 +++++++++++-------- .../Helpers/DeprecationItemsHelper.cs | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/NuGetGallery/Helpers/SearchResponseHelper.cs b/src/NuGetGallery/Helpers/SearchResponseHelper.cs index 46a64c80a6..cb669f2f55 100644 --- a/src/NuGetGallery/Helpers/SearchResponseHelper.cs +++ b/src/NuGetGallery/Helpers/SearchResponseHelper.cs @@ -33,17 +33,21 @@ public static ICollection GetDeprecationsOrNull(JToken docDe if (docAlternatePackage != null) { var range = docAlternatePackage.Value("Range"); - var version = string.Empty; - if (range.StartsWith("[")) + var id = docAlternatePackage.Value("Id"); + if (!string.IsNullOrEmpty(range) && !string.IsNullOrEmpty(id)) { - version = range.Substring(1, range.IndexOf(", )")); - } + var version = string.Empty; + if (range.StartsWith("[")) + { + version = range.Substring(1, range.IndexOf(", )")); + } - alternatePackage = new Package() - { - Id = docAlternatePackage.Value("Id"), - Version = version - }; + alternatePackage = new Package() + { + Id = id, + Version = version + }; + } } deprecation = new PackageDeprecation() @@ -67,7 +71,7 @@ public static ICollection GetVulnerabilities(JArr { Vulnerability = new PackageVulnerability() { - AdvisoryUrl = v.Value("AdvisoryURL"), + AdvisoryUrl = v.Value("AdvisoryUrl"), Severity = (PackageVulnerabilitySeverity)v.Value("Severity") } }) diff --git a/tests/NuGetGallery.Facts/Helpers/DeprecationItemsHelper.cs b/tests/NuGetGallery.Facts/Helpers/DeprecationItemsHelper.cs index 903387d6d9..46ed590bdd 100644 --- a/tests/NuGetGallery.Facts/Helpers/DeprecationItemsHelper.cs +++ b/tests/NuGetGallery.Facts/Helpers/DeprecationItemsHelper.cs @@ -38,12 +38,14 @@ public static IEnumerable ValidObjects { Message = "message", Reasons = new [] { "Other", "Legacy", "CriticalBugs" }, + AlternatePackage = new {} }) }; yield return new object[] { JObject.FromObject(new { Reasons = new [] { "Legacy" }, + AlternatePackage = new {} }) }; }