We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 16ad349 commit 82b8d76Copy full SHA for 82b8d76
hashids.go
@@ -335,13 +335,15 @@ func (h *HashID) DecodeHex(hash string) (string, error) {
335
return "", err
336
}
337
338
- ret := ""
339
- for _, n := range numbers {
340
- nHex := fmt.Sprintf("%X", n)
341
- ret = strings.ToLower(fmt.Sprintf("%s%s", ret, nHex[1:len(nHex)]))
+ const hex = "0123456789abcdef"
+ b := make([]byte, len(numbers))
+ for i, n := range numbers {
+ if n < 0x10 || n > 0x1f {
342
+ return "", errors.New("invalid number")
343
+ }
344
+ b[i] = hex[n-0x10]
345
-
- return ret, nil
346
+ return string(b), nil
347
348
349
func splitRunes(input, seps []rune) [][]rune {
0 commit comments