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
id.go
View File

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