Skip to content

Commit

Permalink
combine update version check
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo authored and randhircs committed Jan 17, 2025
1 parent 9d1e760 commit 57b57a5
Showing 1 changed file with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,18 @@ internal static Func<NuGetVersion, bool> CreateVersionFilter(DependencyInfo depe
var safeVersions = dependencyInfo.Vulnerabilities.SelectMany(v => v.SafeVersions).ToList();
return version =>
{
if (safeVersions.Any())
{
// only consider these
if (safeVersions.Any(s => s.IsSatisfiedBy(version)))
{
return true;
}

return false;
}
else
{
var versionGreaterThanCurrent = currentVersion is null || version > currentVersion;
var rangeSatisfies = versionRange.Satisfies(version);
var prereleaseTypeMatches = currentVersion is null || !currentVersion.IsPrerelease || !version.IsPrerelease || version.Version == currentVersion.Version;
var isIgnoredVersion = dependencyInfo.IgnoredVersions.Any(i => i.IsSatisfiedBy(version));
var isVulnerableVersion = dependencyInfo.Vulnerabilities.Any(v => v.IsVulnerable(version));
return versionGreaterThanCurrent
&& rangeSatisfies
&& prereleaseTypeMatches
&& !isIgnoredVersion
&& !isVulnerableVersion;
}
var versionGreaterThanCurrent = currentVersion is null || version > currentVersion;
var rangeSatisfies = versionRange.Satisfies(version);
var prereleaseTypeMatches = currentVersion is null || !currentVersion.IsPrerelease || !version.IsPrerelease || version.Version == currentVersion.Version;
var isIgnoredVersion = dependencyInfo.IgnoredVersions.Any(i => i.IsSatisfiedBy(version));
var isVulnerableVersion = dependencyInfo.Vulnerabilities.Any(v => v.IsVulnerable(version));
var isSafeVersion = !safeVersions.Any() || safeVersions.Any(s => s.IsSatisfiedBy(version));
return versionGreaterThanCurrent
&& rangeSatisfies
&& prereleaseTypeMatches
&& !isIgnoredVersion
&& !isVulnerableVersion
&& isSafeVersion;
};
}

Expand Down

0 comments on commit 57b57a5

Please sign in to comment.