Skip to content

Commit

Permalink
Fix: zeroes in middle of the name
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Nov 22, 2023
1 parent 0706068 commit 3db205b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmd/api/handler/responses/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package responses

import (
"bytes"
"encoding/hex"
"time"

Expand Down Expand Up @@ -45,16 +46,16 @@ func (Namespace) SearchType() string {
}

func decodeName(nsId []byte) string {
isDecodable := true
data := make([]byte, 0)
for i := range nsId {
if nsId[i] == 0 {
continue
}
if nsId[i] < 0x20 || nsId[i] > 0x7f {
var (
trimmed = bytes.Trim(nsId, "\x00")
data = make([]byte, 0)
isDecodable = true
)
for i := range trimmed {
if trimmed[i] < 0x20 || trimmed[i] > 0x7f {
isDecodable = false
}
data = append(data, nsId[i])
data = append(data, trimmed[i])
}

if isDecodable {
Expand Down
4 changes: 4 additions & 0 deletions cmd/api/handler/responses/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func Test_decodeName(t *testing.T) {
name: "test 3",
nsId: "0000000000000000000000000000000000000000e6edd3ffbef8c7d8",
want: "e6edd3ffbef8c7d8",
}, {
name: "test 4",
nsId: "00000000000000000000000000000000000000e6edd3ffbef8c700d8",
want: "e6edd3ffbef8c700d8",
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 3db205b

Please sign in to comment.