Skip to content

Commit

Permalink
Fix out of bounds for some ref URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed May 16, 2023
1 parent 6d1c961 commit f808c45
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions hit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func TestHitDefaultsRef(t *testing.T) {
{"https://np.reddit.com/r/programming/.compact", "www.reddit.com/r/programming", nil, set, "h"},

{"android-app://com.example.android", "com.example.android", nil, nil, "o"},

{"/?fbclid=PAAaa9RPz6YNKOc1LT4OzcjmuQpMiQl214kJ5YluqNF77eDp8JZQJOazM_GQc", "", nil, nil, "o"},
}

ctx := gctest.DB(t)
Expand Down
7 changes: 4 additions & 3 deletions ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,11 @@ func cleanRefURL(ref string, refURL *url.URL) (string, bool) {
q.Del("__cf_chl_captcha_tk__") // Cloudflare
q.Del("__cf_chl_jschl_tk__")

if len(q) == 0 {
return refURL.String()[2:], false
s := refURL.String()
if len(s) > 1 {
return s[2:], false
}
return refURL.String()[2:], false
return "/", false
}

// ListRefsByPath lists all references for a pathID.
Expand Down

0 comments on commit f808c45

Please sign in to comment.