don't allow computed set elems to be equal

If set elements are computed, we can't be certain that they are actually
equal. Catch identical computed set hashes when they are added to the
set, and alter the set key slightly to keep the set counts correct.

In previous versions the interpolation string would be included in the
set, and different string values would cause the set to hash
differently, so this is change is only activated for the new protocol.
This commit is contained in:
James Bardin 2019-02-04 19:15:43 -05:00
parent 79d1e0d7cf
commit 8be864c1c7
1 changed files with 10 additions and 0 deletions

View File

@ -198,6 +198,16 @@ func (s *Set) add(item interface{}, computed bool) string {
code := s.hash(item)
if computed {
code = "~" + code
if isProto5() {
tmpCode := code
count := 0
for _, exists := s.m[tmpCode]; exists; _, exists = s.m[tmpCode] {
count++
tmpCode = fmt.Sprintf("%s%d", code, count)
}
code = tmpCode
}
}
if _, ok := s.m[code]; !ok {