From 8be864c1c7aabf97d94f81e5588555f6ff49e2da Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 4 Feb 2019 19:15:43 -0500 Subject: [PATCH] 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. --- helper/schema/set.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/helper/schema/set.go b/helper/schema/set.go index cba289035..8ee89e475 100644 --- a/helper/schema/set.go +++ b/helper/schema/set.go @@ -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 {