mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-06 23:13:08 +00:00
Merge pull request #116 from aratz-lasa/patch-1
Validate bytes when parsing string
This commit is contained in:
commit
8f388501b1
@ -14,8 +14,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Transcoder interface {
|
type Transcoder interface {
|
||||||
|
// Validates and encodes to bytes a multiaddr that's in the string representation.
|
||||||
StringToBytes(string) ([]byte, error)
|
StringToBytes(string) ([]byte, error)
|
||||||
|
// Validates and decodes to a string a multiaddr that's in the bytes representation.
|
||||||
BytesToString([]byte) (string, error)
|
BytesToString([]byte) (string, error)
|
||||||
|
// Validates bytes when parsing a multiaddr that's already in the bytes representation.
|
||||||
ValidateBytes([]byte) error
|
ValidateBytes([]byte) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +66,9 @@ func ip6zoneStB(s string) ([]byte, error) {
|
|||||||
if len(s) == 0 {
|
if len(s) == 0 {
|
||||||
return nil, fmt.Errorf("empty ip6zone")
|
return nil, fmt.Errorf("empty ip6zone")
|
||||||
}
|
}
|
||||||
|
if strings.Contains(s, "/") {
|
||||||
|
return nil, fmt.Errorf("IPv6 zone ID contains '/': %s", s)
|
||||||
|
}
|
||||||
return []byte(s), nil
|
return []byte(s), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user