Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
refactor parse urls
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Aug 30, 2023
1 parent 4a3d1d6 commit 5a8a2de
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions common/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,16 +555,9 @@ func filterCookies(cookies []*api.Cookie, urls ...string) ([]*api.Cookie, error)
return cookies, nil
}

// parse the given URLs.
purls := make([]*url.URL, len(urls))
for i, u := range urls {
uri, err := url.ParseRequestURI(
strings.TrimSpace(u),
)
if err != nil {
return nil, fmt.Errorf("parsing URL %q: %w", u, err)
}
purls[i] = uri
purls, err := parseURLs(urls...)
if err != nil {
return nil, fmt.Errorf("parsing URLs: %w", err)
}

// the following algorithm is like a sorting algorithm,
Expand Down Expand Up @@ -654,3 +647,20 @@ func shouldFilterCookie(c *api.Cookie, uri *url.URL) bool {
// Keep the cookie.
return true
}

// parseURLs parses the given URLs.
// If an error occurs while parsing a URL, the error is returned.
func parseURLs(urls ...string) ([]*url.URL, error) {
purls := make([]*url.URL, len(urls))
for i, u := range urls {
uri, err := url.ParseRequestURI(
strings.TrimSpace(u),
)
if err != nil {
return nil, fmt.Errorf("%q: %w", u, err)
}
purls[i] = uri
}

return purls, nil
}

0 comments on commit 5a8a2de

Please sign in to comment.