From 4856ed5251af618e9fcdd7e9b221546fa287ced6 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Wed, 17 Apr 2013 19:00:42 -0700 Subject: [PATCH] Change sha1 mutation hash to use a separator between strings * When concatenating strings together to hash you need to use a separator that does not exist in the strings, otherwise you can easily get duplicate hashes, eg: Digest::SHA1.hexdigest('ab' + 'c') # => "a9993e364706816aba3e25717850c26c9cd0d89d" Digest::SHA1.hexdigest('a' + 'bc') # => "a9993e364706816aba3e25717850c26c9cd0d89d" Using a null character as a separator works around this problem: Digest::SHA1.hexdigest('a' + 0.chr + 'bc') # => "0b2749668f0ea8df8a630da13f0d218709efd5ca" Digest::SHA1.hexdigest('ab' + 0.chr + 'c') # => "dbdd4f85d8a56500aa5c9c8a0d456f96280c92e5" --- lib/mutant/mutation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mutant/mutation.rb b/lib/mutant/mutation.rb index a3fa6b49..98e54ae4 100644 --- a/lib/mutant/mutation.rb +++ b/lib/mutant/mutation.rb @@ -97,7 +97,7 @@ module Mutant # @api private # def sha1 - Digest::SHA1.hexdigest(subject.identification + source) + Digest::SHA1.hexdigest(subject.identification + 0.chr + source) end memoize :sha1