Skip to content

Commit

Permalink
fix: md5 not empty when content is empty (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
EndlessSeeker authored Oct 11, 2024
1 parent 4464edc commit 7b95c9d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions util/md5.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions util/md5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ import (
func TestMd5(t *testing.T) {
md5 := Md5("demo")
assert.Equal(t, "fe01ce2a7fbac8fafaed7c982a04e229", md5)

md5 = Md5("")
assert.Equal(t, "", md5)
}

0 comments on commit 7b95c9d

Please sign in to comment.