Merge pull request #7109 from CodeMonk/pkg_version_fix

Fix for when version is nil
This commit is contained in:
Mike McQuaid 2020-03-04 11:46:05 +00:00 committed by GitHub
commit 89fd3cc234
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -36,7 +36,10 @@ class PkgVersion
def <=>(other)
return unless other.is_a?(PkgVersion)
(version <=> other.version).nonzero? || revision <=> other.revision
version_comparison = (version <=> other.version)
return if version_comparison.nil?
version_comparison.nonzero? || revision <=> other.revision
end
alias eql? ==

View File

@ -54,6 +54,11 @@ describe PkgVersion do
describe "#<=>" do
it "returns nil if the comparison fails" do
expect(described_class.new(Version.create("1.0"), 0) <=> Object.new).to be nil
expect(Object.new <=> described_class.new(Version.create("1.0"), 0)).to be nil
expect(Object.new <=> described_class.new(Version.create("1.0"), 0)).to be nil
expect(described_class.new(Version.create("1.0"), 0) <=> nil).to be nil
# This one used to fail due to dereferencing a null `self`
expect(described_class.new(nil, 0) <=> described_class.new(Version.create("1.0"), 0)).to be nil
end
end