Skip to content

Commit

Permalink
refactor: standardize URL validation and move it to config package
Browse files Browse the repository at this point in the history
  • Loading branch information
revelaction committed Sep 30, 2024
1 parent abcc803 commit fc1d4eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func Load(data []byte) (Config, error) {
data, err := decodeBase64URI(im.Value)
if err != nil {
// try external URL
errUrl := validateUrl(im.Value)
errUrl := ValidateUrl(im.Value)
if errUrl != nil {
return Config{}, fmt.Errorf("Image %d error: bad base64 format[%w], bad Url format [%w]", i, err, errUrl)
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func decodeBase64URI(s string) ([]byte, error) {
return decodedData, nil
}

func validateUrl(urlStr string) error {
func ValidateUrl(urlStr string) error {
u, err := url.Parse(urlStr)
if err != nil {
return fmt.Errorf("invalid URL format: %v", err)
Expand Down
12 changes: 7 additions & 5 deletions ical/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ func (p *Parser) buildNotification(event *ics.VEvent) notify.Notification {
n.ImageName = image.Name
}
} else {
// only external Url
// check https TODO
if seemsImageFile(imageUrlProp.Value) {
n.ImageUrl = imageUrlProp.Value
n.ImageName = imageUrlProp.Value
// TODO move validation from config
err := config.ValidateUrl(imageUrlProp.Value)
if err == nil {
if seemsImageFile(imageUrlProp.Value) {
n.ImageUrl = imageUrlProp.Value
n.ImageName = imageUrlProp.Value
}
}
}
}
Expand Down

0 comments on commit fc1d4eb

Please sign in to comment.