Skip to content

Commit

Permalink
AdvisoryUrl, and AlternatePackage fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyjdev committed Apr 21, 2023
1 parent d172121 commit 6227551
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/NuGetGallery/Helpers/SearchResponseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ public static ICollection<PackageDeprecation> GetDeprecationsOrNull(JToken docDe
if (docAlternatePackage != null)
{
var range = docAlternatePackage.Value<string>("Range");
var version = string.Empty;
if (range.StartsWith("["))
var id = docAlternatePackage.Value<string>("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<string>("Id"),
Version = version
};
alternatePackage = new Package()
{
Id = id,
Version = version
};
}
}

deprecation = new PackageDeprecation()
Expand All @@ -67,7 +71,7 @@ public static ICollection<VulnerablePackageVersionRange> GetVulnerabilities(JArr
{
Vulnerability = new PackageVulnerability()
{
AdvisoryUrl = v.Value<string>("AdvisoryURL"),
AdvisoryUrl = v.Value<string>("AdvisoryUrl"),
Severity = (PackageVulnerabilitySeverity)v.Value<int>("Severity")
}
})
Expand Down
2 changes: 2 additions & 0 deletions tests/NuGetGallery.Facts/Helpers/DeprecationItemsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public static IEnumerable<object[]> ValidObjects
{
Message = "message",
Reasons = new [] { "Other", "Legacy", "CriticalBugs" },
AlternatePackage = new {}
})
};
yield return new object[] {
JObject.FromObject(new
{
Reasons = new [] { "Legacy" },
AlternatePackage = new {}
})
};
}
Expand Down

0 comments on commit 6227551

Please sign in to comment.