This patch incorporates the below upstream fixes from RubyGems 2.3.0
The patch should be removed for Ruby 2.2.x and above, which includes
RubyGems 2.3.0+.
Check for prerelease in Dependency#match?
https://github.com/rubygems/rubygems/commit/d9c25c5d65f47117f3c458136ee1f1030d6ddbe1
Open dependencies no longer match prereleases
https://github.com/rubygems/rubygems/commit/0936ca6929172d28b15220dfef8526a9645a90ce
If a dependency is open ended (>= 0) it should not match a prerelease
dependency.
Fix Dependency#match? for prereleases
https://github.com/rubygems/rubygems/commit/1b98dc1528d015413e2faded6354203217e58bfe
Checking for @prerelease is insufficient as the flag is never set to
true. Now we use the prerelease? method which correctly determines if
the dependency can match prerelease versions.
Test Gem::Dependency#match?
https://github.com/rubygems/rubygems/commit/c8362d0373f6d9d0bc4a9b4ab3a76712aaab6e9e
--- ruby-2.1.6-orig/lib/rubygems/dependency.rb 2013-09-14 01:59:02.000000000 -0700
+++ ruby-2.1.6/lib/rubygems/dependency.rb 2016-06-15 09:15:30.867335532 -0700
@@ -216,7 +216,11 @@ class Gem::Dependency
end
return false unless self.name === name
- return true if requirement.none?
+
+ version = Gem::Version.new version
+
+ return true if requirement.none? and not version.prerelease?
+ return false if version.prerelease? and not prerelease?
requirement.satisfied_by? Gem::Version.new(version)
end
--- ruby-2.1.6-orig/test/rubygems/test_gem_dependency.rb 2012-11-28 22:52:18.000000000 -0800
+++ ruby-2.1.6/test/rubygems/test_gem_dependency.rb 2016-06-15 11:31:40.692189618 -0700
@@ -28,6 +28,16 @@ class TestGemDependency < Gem::TestCase
assert_equal req(">= 0"), d.requirement
end
+ def test_initialize_prerelease
+ d = dep 'd', '1.a'
+
+ assert d.prerelease?
+
+ d = dep 'd', '= 1.a'
+
+ assert d.prerelease?
+ end
+
def test_initialize_type
assert_equal :runtime, dep("pkg").type
assert_equal :development, dep("pkg", [], :development).type
@@ -115,6 +125,60 @@ class TestGemDependency < Gem::TestCase
refute_equal dep("pkg", :development), dep("pkg", :runtime), "type"
end
+ def test_match_eh_name_tuple
+ a_dep = dep 'a'
+
+ a_tup = Gem::NameTuple.new 'a', 1
+ b_tup = Gem::NameTuple.new 'b', 2
+ c_tup = Gem::NameTuple.new 'c', '2.a'
+
+ assert a_dep.match? a_tup
+ refute a_dep.match? b_tup
+
+ b_dep = dep 'b', '>= 3'
+
+ refute b_dep.match? b_tup
+
+ c_dep = dep 'c', '>= 1'
+
+ refute c_dep.match? c_tup
+
+ c_dep = dep 'c'
+
+ refute c_dep.match? c_tup
+
+ c_dep = dep 'c', '2.a'
+
+ assert c_dep.match? c_tup
+ end
+
+ def test_match_eh_specification
+ a_dep = dep 'a'
+
+ a_spec = util_spec 'a', 1
+ b_spec = util_spec 'b', 2
+ c_spec = util_spec 'c', '2.a'
+
+ assert a_dep.match? a_spec
+ refute a_dep.match? b_spec
+
+ b_dep = dep 'b', '>= 3'
+
+ refute b_dep.match? b_spec
+
+ c_dep = dep 'c', '>= 1'
+
+ refute c_dep.match? c_spec
+
+ c_dep = dep 'c'
+
+ refute c_dep.match? c_spec
+
+ c_dep = dep 'c', '2.a'
+
+ assert c_dep.match? c_spec
+ end
+
def test_merge
a1 = dep 'a', '~> 1.0'
a2 = dep 'a', '= 1.0'