Skip to content

Commit

Permalink
allow empty version after comma in a requirement (#10713)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo authored Oct 2, 2024
1 parent 03aa6dc commit 911bcb4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ public void IsSatisfiedBy(string versionString, string requirementString, bool e
}

[Theory]
[InlineData("> *", "> 0")] // standard wildcard, no digits
[InlineData("> 1.*", "> 1.0")] // standard wildcard, single digit
[InlineData("> 1.2.*", "> 1.2.0")] // standard wildcard, multiple digit
[InlineData("> a", "> 0")] // alternate wildcard, no digits
[InlineData("> 1.a", "> 1.0")] // alternate wildcard, single digit
[InlineData("> 1.2.a", "> 1.2.0")] // alternate wildcard, multiple digit
public void Parse_ConvertsWildcardInVersion(string givenRequirementString, string expectedRequirementString)
[InlineData(">= 1.40.0, ", ">= 1.40.0")] // empty string following comma
public void Parse_Requirement(string givenRequirementString, string expectedRequirementString)
{
var parsedRequirement = Requirement.Parse(givenRequirementString);
var actualRequirementString = parsedRequirement.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public static Version Bump(NuGetVersion version)

public static Requirement Parse(string requirement)
{
var specificParts = requirement.Split(',');
var specificParts = requirement.Split(',').Where(p => !string.IsNullOrWhiteSpace(p)).ToArray();
if (specificParts.Length == 1)
{
return IndividualRequirement.ParseIndividual(requirement);
return IndividualRequirement.ParseIndividual(specificParts[0]);
}

var specificRequirements = specificParts.Select(IndividualRequirement.ParseIndividual).ToArray();
Expand Down
2 changes: 2 additions & 0 deletions nuget/lib/dependabot/nuget/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def initialize(*requirements)
convert_dotnet_constraint_to_ruby_constraint(req_string)
end

requirements = requirements.compact.reject(&:empty?)

super(requirements)
end

Expand Down
6 changes: 6 additions & 0 deletions nuget/spec/dependabot/nuget/requirement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
it { is_expected.to eq(Gem::Requirement.new(">= 1.0.0", "< 2.0.0")) }
end

context "when an empty string follows a comma" do
let(:requirement_string) { ">= 1.40.0, " }

it { is_expected.to eq(Gem::Requirement.new(">= 1.40.0")) }
end

context "when including a * in the lower bound" do
let(:requirement_string) { "[2.1.*,3.0.0)" }

Expand Down

0 comments on commit 911bcb4

Please sign in to comment.