From 472d1a22c5748cdba710dcbd19b31279edeaeaa0 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sat, 26 May 2018 14:41:37 +0200 Subject: [PATCH] Fix comparison with Version::NULL on RHS This was accounted for in Version::NULL.<=>, but not in Version#<=>, so these could only be compared if Version::NULL was the left hand side. The check had to go above the check that `other` is a version because `Version::NULL`'s anonymous class does not inherit from `Version`. (The type check feels like it's probably a smell, but out of scope). --- Library/Homebrew/test/version_spec.rb | 4 ++++ Library/Homebrew/version.rb | 1 + 2 files changed, 5 insertions(+) diff --git a/Library/Homebrew/test/version_spec.rb b/Library/Homebrew/test/version_spec.rb index a713d6369b..c80998e528 100644 --- a/Library/Homebrew/test/version_spec.rb +++ b/Library/Homebrew/test/version_spec.rb @@ -144,6 +144,10 @@ describe Version do expect(described_class.create("2.1.0-p194")).to be > nil end + it "can be compared against Version::NULL" do + expect(described_class.create("2.1.0-p194")).to be > Version::NULL + end + it "can be compared against strings" do expect(described_class.create("2.1.0-p194")).to be == "2.1.0-p194" expect(described_class.create("1")).to be == 1 diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index c2635f18cc..b6c0a79abc 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -387,6 +387,7 @@ class Version other = Version.new(other.to_s) if other.is_a? Integer return 1 if other.nil? + return 1 if other.respond_to?(:null?) && other.null? return unless other.is_a?(Version) return 0 if version == other.version return 1 if head? && !other.head?