From 58dd8f47708f66ef88734d86758341c51c71d858 Mon Sep 17 00:00:00 2001 From: Alexander Mancevice Date: Sat, 24 Mar 2018 09:04:51 -0400 Subject: [PATCH] Defensive check for Checksum == nil Protects against NoMethodError when checking a Checksum instance with a bad 'other' --- Library/Homebrew/checksum.rb | 2 +- Library/Homebrew/test/checksum_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/checksum.rb b/Library/Homebrew/checksum.rb index 506885fce3..c1d0e70551 100644 --- a/Library/Homebrew/checksum.rb +++ b/Library/Homebrew/checksum.rb @@ -13,6 +13,6 @@ class Checksum delegate [:empty?, :to_s] => :@hexdigest def ==(other) - hash_type == other.hash_type && hexdigest == other.hexdigest + hash_type == other&.hash_type && hexdigest == other.hexdigest end end diff --git a/Library/Homebrew/test/checksum_spec.rb b/Library/Homebrew/test/checksum_spec.rb index acab348b7e..01cfd29d13 100644 --- a/Library/Homebrew/test/checksum_spec.rb +++ b/Library/Homebrew/test/checksum_spec.rb @@ -15,5 +15,6 @@ describe Checksum do it { is_expected.to eq(other) } it { is_expected.not_to eq(other_reversed) } it { is_expected.not_to eq(other_sha1) } + it { is_expected.not_to eq(nil) } end end