diff --git a/random/random.go b/random/random.go index 282241b..aac04d8 100644 --- a/random/random.go +++ b/random/random.go @@ -43,6 +43,10 @@ func New() *Random { } func (r *Random) String(length uint8, charsets ...string) string { + if length == 0 { + return "" + } + charset := strings.Join(charsets, "") if charset == "" { charset = Alphanumeric diff --git a/random/random_test.go b/random/random_test.go index 5927dcf..0b26f9b 100644 --- a/random/random_test.go +++ b/random/random_test.go @@ -28,6 +28,10 @@ func TestRandomString(t *testing.T) { name: "ok, 32", whenLength: 32, }, + { + name: "ok, 0", + whenLength: 0, + }, } for _, tc := range testCases {