Skip to content

Commit

Permalink
(bug) fix relative to absolute
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed May 6, 2024
1 parent 3b1ca40 commit b04700d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/Extractor.astro
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;
for="input-depth"
class="block mb-2 text-sm font-medium text-slate-400"
>
Depth <sup class="text-xs text-slate-500">-1 to 5</sup>
Depth <sup class="text-xs text-slate-500">-1 to 20</sup>
</label>
<input
id="input-depth"
Expand Down Expand Up @@ -220,7 +220,7 @@ const baseURL = import.meta.env.PUBLIC_BASE_URL;
baseURL = baseURL.startsWith("http") ? baseURL : currentURL + baseURL;
let input = Alpine.reactive({
url: "",
depth: 2,
depth: 1,
ignore_queries: true,
limit_urls: 1000,
limit_emails: 10000,
Expand Down
2 changes: 1 addition & 1 deletion pkg/extract_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewExtractHandler() *ExtractHandler {

type ExtractorRequest struct {
URL string `json:"url" query:"url" validate:"required" message:"url is required"`
Depth int `json:"depth" query:"depth" default:"1" validate:"required,numeric,gte=-1,lte=5" message:"depth must be a number between -1 and 5"`
Depth int `json:"depth" query:"depth" default:"1" validate:"required,numeric,gte=-1,lte=5" message:"depth must be a number between -1 and 20"`
IgnoreQueries string `json:"ignore_queries" default:"true" query:"ignore_queries" validate:"required,eq=true|eq=false" message:"ignore_queries must be true or false"`
LimitUrls int `json:"limit_urls" query:"limit_urls" default:"100" validate:"required,numeric,gte=1,lte=1000" message:"limit_urls must be a number between 1 and 1000"`
LimitEmails int `json:"limit_emails" query:"limit_emails" default:"1000" validate:"required,numeric,gte=1,lte=10000" message:"limit_emails must be a number between 1 and 10000"`
Expand Down
29 changes: 21 additions & 8 deletions pkg/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,32 @@ func RelativeToAbsoluteURL(href, currentURL, baseURL string) string {
if strings.HasPrefix(href, "http") {
return href
}
// ignore if it is javascript:void(0)
if strings.HasPrefix(href, "javascript:void(0)") {
return ""
// Parse the URLs
u, err := url.Parse(href)
if err != nil {
return "" // handle error, return empty string or appropriate value
}

if strings.HasPrefix(href, "/") {
return baseURL + href
// If href is absolute, return it directly
if u.IsAbs() {
return u.String()
}
if strings.HasPrefix(href, "./") {
return currentURL + href[2:]

// Use baseURL if currentURL is not provided
if currentURL == "" {
parsedBaseURL, err := url.Parse(baseURL)
if err != nil {
return "" // handle error, return empty string or appropriate value
}
return parsedBaseURL.ResolveReference(u).String()
}

return currentURL + href
// Resolve the relative URL using currentURL
parsedCurrentURL, err := url.Parse(currentURL)
if err != nil {
return "" // handle error, return empty string or appropriate value
}
return parsedCurrentURL.ResolveReference(u).String()
}

func CountPerDomain(emails []string) map[string]int {
Expand Down

0 comments on commit b04700d

Please sign in to comment.