mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 20:47:49 +00:00
Fixed low-level bug that failed to deal with null/empty hashing.
Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
@@ -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
|
// GenerateHashString will generate a SHA36 hash of any object passed in. If the object is Hashable
|
||||||
// then the underlying Hash() method will be called.
|
// then the underlying Hash() method will be called.
|
||||||
func GenerateHashString(v any) string {
|
func GenerateHashString(v any) string {
|
||||||
|
if v == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
if h, ok := v.(Hashable); ok {
|
if h, ok := v.(Hashable); ok {
|
||||||
if h != nil {
|
if h != nil {
|
||||||
return fmt.Sprintf(HASH, h.Hash())
|
return fmt.Sprintf(HASH, h.Hash())
|
||||||
|
|||||||
@@ -1669,6 +1669,12 @@ func TestGenerateHashString(t *testing.T) {
|
|||||||
assert.Equal(t, "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824",
|
assert.Equal(t, "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824",
|
||||||
GenerateHashString("hello"))
|
GenerateHashString("hello"))
|
||||||
|
|
||||||
|
assert.Equal(t, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||||
|
GenerateHashString(""))
|
||||||
|
|
||||||
|
assert.Equal(t, "",
|
||||||
|
GenerateHashString(nil))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateHashString_Pointer(t *testing.T) {
|
func TestGenerateHashString_Pointer(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user