Check uris before applying them

This commit is contained in:
2024-10-17 19:28:09 +02:00
parent cb61d90cae
commit 6117876a59
5 changed files with 32 additions and 10 deletions

10
icon.go
View File

@@ -10,9 +10,13 @@ type Icon struct {
URI IRI `xml:",chardata"`
}
// NewIcon creates a new Icon. It returns a *Icon.
func NewIcon(uri string) *Icon {
return &Icon{URI: IRI(uri)}
// NewIcon creates a new Icon. It returns a *Icon and an error.
func NewIcon(uri IRI) (*Icon, error) {
if !isValidIRI(uri) {
return nil, fmt.Errorf("uri %v not correctly formatted", uri)
}
return &Icon{URI: uri}, nil
}
// Check checks the Icon for incompatibilities with RFC4287. It returns an