mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
id: validate server names in UserID.ParseAndValidate
This commit is contained in:
parent
8fb04d1806
commit
522a373c68
1 changed files with 8 additions and 4 deletions
12
id/userid.go
12
id/userid.go
|
|
@ -30,10 +30,11 @@ func NewEncodedUserID(localpart, homeserver string) UserID {
|
|||
}
|
||||
|
||||
var (
|
||||
ErrInvalidUserID = errors.New("is not a valid user ID")
|
||||
ErrNoncompliantLocalpart = errors.New("contains characters that are not allowed")
|
||||
ErrUserIDTooLong = errors.New("the given user ID is longer than 255 characters")
|
||||
ErrEmptyLocalpart = errors.New("empty localparts are not allowed")
|
||||
ErrInvalidUserID = errors.New("is not a valid user ID")
|
||||
ErrNoncompliantLocalpart = errors.New("contains characters that are not allowed")
|
||||
ErrUserIDTooLong = errors.New("the given user ID is longer than 255 characters")
|
||||
ErrEmptyLocalpart = errors.New("empty localparts are not allowed")
|
||||
ErrNoncompliantServerPart = errors.New("is not a valid server name")
|
||||
)
|
||||
|
||||
// ParseCommonIdentifier parses a common identifier according to https://spec.matrix.org/v1.9/appendices/#common-identifier-format
|
||||
|
|
@ -113,6 +114,9 @@ func (userID UserID) ParseAndValidate() (localpart, homeserver string, err error
|
|||
if err == nil && len(userID) > UserIDMaxLength {
|
||||
err = ErrUserIDTooLong
|
||||
}
|
||||
if err == nil && !ValidateServerName(homeserver) {
|
||||
err = fmt.Errorf("%q %q", homeserver, ErrNoncompliantServerPart)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue