Check uris before applying them

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

View File

@ -62,8 +62,13 @@ func NewEntry(title string) (*Entry, error) {
return nil, fmt.Errorf("error creating new entry: %v", err)
}
id, err := NewID(NewURN())
if err != nil {
return nil, fmt.Errorf("error creating new entry: %v", err)
}
return &Entry{
ID: NewID(NewURN()),
ID: id,
Title: text,
Updated: NewDate(time.Now()),
}, nil

View File

@ -33,8 +33,13 @@ func NewFeed(title string) (*Feed, error) {
return nil, fmt.Errorf("error creating new feed: %v", err)
}
id, err := NewID(NewURN())
if err != nil {
return nil, fmt.Errorf("error creating new feed: %v", err)
}
return &Feed{
ID: NewID(NewURN()),
ID: id,
Title: text,
Updated: NewDate(time.Now()),
}, nil

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

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.

View File

@ -11,8 +11,12 @@ type Logo struct {
}
// NewLogo creates a new Logo. It returns a *Logo.
func NewLogo(uri string) *Logo {
return &Logo{URI: IRI(uri)}
func NewLogo(uri IRI) (*Logo, error) {
if !isValidIRI(uri) {
return nil, fmt.Errorf("uri %v not correctly formatted", uri)
}
return &Logo{URI: uri}, nil
}
// Check checks the Logo for incompatibilities with RFC4287. It returns an