Skip to content

Commit

Permalink
Gradle: fix comparison of the prefix version range (#7975)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoffman authored Sep 5, 2023
1 parent 853aada commit 68a2f5e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gradle/lib/dependabot/gradle/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ def pad_for_comparison(prefixed_tokens, other_prefixed_tokens)
end

def compare_prefixed_token(prefix:, token:, other_prefix:, other_token:)
return 1 if token == "+" && other_token != "+"
return -1 if other_token == "+" && token != "+"
return 0 if token == "+" && other_token == "+"

token_type = token.match?(/^\d+$/) ? :number : :qualifier
other_token_type = other_token.match?(/^\d+$/) ? :number : :qualifier

Expand Down
25 changes: 25 additions & 0 deletions gradle/spec/dependabot/gradle/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,31 @@
let(:other_version) { described_class.new("1-alpha-1") }
it { is_expected.to eq(0) }
end

context "dynamic minor version" do
let(:version) { described_class.new("1.+") }

it "is greater than a non-dynamic version" do
expect(version).to be > described_class.new("1.11")
expect(version).to be > described_class.new("1.11.1")
end

it "is less than the next major version" do
expect(version).to be < described_class.new("2.0")
end
end

context "dynamic patch version" do
let(:version) { described_class.new("1.1.+") }

it "is greater than a non-dynamic version" do
expect(version).to be > described_class.new("1.1.2")
end

it "is less than the next minor version" do
expect(version).to be < described_class.new("1.2")
end
end
end
end
end
Expand Down

0 comments on commit 68a2f5e

Please sign in to comment.