diff --git a/util/md5.go b/util/md5.go index 6ece2761..9bd64d6f 100644 --- a/util/md5.go +++ b/util/md5.go @@ -23,6 +23,10 @@ import ( ) func Md5(content string) (md string) { + if content == "" { + return + } + h := md5.New() _, _ = io.WriteString(h, content) md = fmt.Sprintf("%x", h.Sum(nil)) diff --git a/util/md5_test.go b/util/md5_test.go index 36b2b49c..206c7d0b 100644 --- a/util/md5_test.go +++ b/util/md5_test.go @@ -25,4 +25,7 @@ import ( func TestMd5(t *testing.T) { md5 := Md5("demo") assert.Equal(t, "fe01ce2a7fbac8fafaed7c982a04e229", md5) + + md5 = Md5("") + assert.Equal(t, "", md5) }