Skip to content

Commit 241d6f5

Browse files
committed
Merge pull request #96 from supershabam/master
only index into host array if element exists
2 parents dbc3cec + fbffde5 commit 241d6f5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

go/refererparser.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ func lookup(uri *url.URL, q string, suffix bool) (refResult *RefererResult) {
8585
func Parse(uri string) (refResult *RefererResult) {
8686
puri, _ := url.Parse(uri)
8787
// Split before the first dot ".".
88-
rhost := strings.SplitAfterN(puri.Host, ".", 2)[1]
88+
parts := strings.SplitAfterN(puri.Host, ".", 2)
89+
rhost := ""
90+
if len(parts) > 1 {
91+
rhost = parts[1]
92+
}
8993
queries := []string{puri.Host + puri.Path, rhost + puri.Path, puri.Host, rhost}
9094
for _, q := range queries {
9195
refResult = lookup(puri, q, false)

go/refererparser_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ var testData = []struct {
236236
"",
237237
false,
238238
},
239+
{
240+
"Referrer with no dot in host",
241+
"http://localhost/search?q=test",
242+
"unknown",
243+
"",
244+
"",
245+
false,
246+
},
239247
}
240248

241249
func check(err error) {

0 commit comments

Comments
 (0)