Skip to content

Commit 8f38850

Browse files
authored
Merge pull request #116 from aratz-lasa/patch-1
Validate bytes when parsing string
2 parents 64e3415 + b00b4ac commit 8f38850

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

transcoders.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ import (
1414
)
1515

1616
type Transcoder interface {
17+
// Validates and encodes to bytes a multiaddr that's in the string representation.
1718
StringToBytes(string) ([]byte, error)
19+
// Validates and decodes to a string a multiaddr that's in the bytes representation.
1820
BytesToString([]byte) (string, error)
21+
// Validates bytes when parsing a multiaddr that's already in the bytes representation.
1922
ValidateBytes([]byte) error
2023
}
2124

@@ -63,6 +66,9 @@ func ip6zoneStB(s string) ([]byte, error) {
6366
if len(s) == 0 {
6467
return nil, fmt.Errorf("empty ip6zone")
6568
}
69+
if strings.Contains(s, "/") {
70+
return nil, fmt.Errorf("IPv6 zone ID contains '/': %s", s)
71+
}
6672
return []byte(s), nil
6773
}
6874

0 commit comments

Comments
 (0)