Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Fix string padding removal from prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel committed May 19, 2016
1 parent e222a80 commit f44b3a4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion util/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ func RandomID(prefix string) (string, error) {
if err != nil {
return "", err
}
str := prefix + base32.StdEncoding.EncodeToString(buf)
str := base32.StdEncoding.EncodeToString(buf)
str = strings.Replace(str, "=", "", -1)
str = prefix + str
return str, nil
}

Expand Down
4 changes: 2 additions & 2 deletions util/rand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
)

func TestRandString(t *testing.T) {
s, err := RandomID("prefix.")
s, err := RandomID("prefix=")
t.Logf("Rand string: %s", s)
if err != nil {
t.Fatal(err)
}
if !strings.HasPrefix(s, "prefix.") {
if !strings.HasPrefix(s, "prefix=") {
t.Errorf("Invalid prefix: %s", s)
}
if len(s)-len("prefix.") != 52 {
Expand Down

0 comments on commit f44b3a4

Please sign in to comment.