未验证 提交 3bfa59bd 编辑于 作者: Markus Reiter's avatar Markus Reiter 提交者: GitHub
浏览文件

Merge pull request #10955 from reitermarkus/bundle-version-comparison

Fix `BundleVersion` comparison when one part is `nil`.
......@@ -10,6 +10,8 @@ module Homebrew
class BundleVersion
extend T::Sig
include Comparable
extend SystemCommand::Mixin
sig { params(info_plist_path: Pathname).returns(T.nilable(T.attached_class)) }
......@@ -55,9 +57,14 @@ module Homebrew
end
def <=>(other)
[version, short_version].map { |v| v&.yield_self(&Version.public_method(:new)) } <=>
[other.version, other.short_version].map { |v| v&.yield_self(&Version.public_method(:new)) }
[version, short_version].map { |v| v&.yield_self(&Version.public_method(:new)) || Version::NULL } <=>
[other.version, other.short_version].map { |v| v&.yield_self(&Version.public_method(:new)) || Version::NULL }
end
def ==(other)
instance_of?(other.class) && short_version == other.short_version && version == other.version
end
alias eql? ==
# Create a nicely formatted version (on a best effort basis).
sig { returns(String) }
......
......@@ -26,4 +26,10 @@ describe Homebrew::BundleVersion do
end
end
end
describe "#<=>" do
it "does not fail when a `version` is nil" do
expect(described_class.new("1.06", nil)).to be < described_class.new("1.12", "1.12")
end
end
end
Supports Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册