Skip to content

Commit

Permalink
fix(result): construct result check for proper url
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksasiriski committed Nov 21, 2024
1 parent c7575cc commit e1a1c66
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/search/result/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package result

import (
"fmt"
"net/url"

"github.com/hearchco/agent/src/search/engines"
)
Expand All @@ -11,6 +12,15 @@ func ConstructResult(seName engines.Name, urll string, title string, description
return WebScraped{}, fmt.Errorf("invalid URL: empty")
}

u, err := url.Parse(urll)
if err != nil {
return WebScraped{}, fmt.Errorf("invalid URL: %s", err)
}

if u.Hostname() == "" {
return WebScraped{}, fmt.Errorf("invalid URL: no hostname")
}

if title == "" {
return WebScraped{}, fmt.Errorf("invalid title: empty")
}
Expand All @@ -24,7 +34,7 @@ func ConstructResult(seName engines.Name, urll string, title string, description
}

return WebScraped{
url: urll,
url: u.String(),
title: title,
description: description,
rank: RankScraped{
Expand Down

0 comments on commit e1a1c66

Please sign in to comment.