From f05abdbcb59e66c9ef5946feb13a5151f34ebf6a Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Wed, 9 Aug 2023 07:33:19 -0400 Subject: [PATCH] Fixed low-level bug that failed to deal with null/empty hashing. Signed-off-by: Dave Shanley --- datamodel/low/extraction_functions.go | 3 +++ datamodel/low/extraction_functions_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/datamodel/low/extraction_functions.go b/datamodel/low/extraction_functions.go index 05b55fa..0d0239f 100644 --- a/datamodel/low/extraction_functions.go +++ b/datamodel/low/extraction_functions.go @@ -698,6 +698,9 @@ func AreEqual(l, r Hashable) bool { // GenerateHashString will generate a SHA36 hash of any object passed in. If the object is Hashable // then the underlying Hash() method will be called. func GenerateHashString(v any) string { + if v == nil { + return "" + } if h, ok := v.(Hashable); ok { if h != nil { return fmt.Sprintf(HASH, h.Hash()) diff --git a/datamodel/low/extraction_functions_test.go b/datamodel/low/extraction_functions_test.go index 57ae5c4..77976fe 100644 --- a/datamodel/low/extraction_functions_test.go +++ b/datamodel/low/extraction_functions_test.go @@ -1669,6 +1669,12 @@ func TestGenerateHashString(t *testing.T) { assert.Equal(t, "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824", GenerateHashString("hello")) + assert.Equal(t, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + GenerateHashString("")) + + assert.Equal(t, "", + GenerateHashString(nil)) + } func TestGenerateHashString_Pointer(t *testing.T) {