Skip to content

Commit

Permalink
Add a new google bot user agent format
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Raddon committed Sep 18, 2018
1 parent d7bd3b0 commit 57c3298
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ var uastrings = []struct {
ua: "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
expected: "Mozilla:5.0 Browser:Googlebot-2.1 Bot:true Mobile:true",
},
{
title: "GoogleBotEmulateMozilla",
ua: "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36",
expected: "Mozilla:5.0 Browser:Googlebot-2.1 Bot:true Mobile:false",
},
{
title: "BingBot",
ua: "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
Expand Down
4 changes: 3 additions & 1 deletion bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func getFromSite(comment []string) string {
idx := 2
if len(comment) < 3 {
idx = 0
} else if len(comment) == 4 {
idx = 3
}

// Pick the site.
Expand All @@ -34,7 +36,7 @@ func getFromSite(comment []string) string {

// This is a large comment, usually the name will be in the previous
// field of the comment.
return strings.TrimSpace(comment[1])
return strings.TrimSpace(comment[idx-1])
}
return ""
}
Expand Down
7 changes: 7 additions & 0 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ func (p *UserAgent) detectBrowser(sections []section) {
} else {
p.browser.Name = "Safari"
}
// Its possible the google-bot emulates these now
for _, comment := range engine.comment {
if len(comment) > 5 && strings.HasPrefix(comment, "Googlebot") {
p.undecided = true
break
}
}
}
} else if engine.name == "Gecko" {
name := sections[2].name
Expand Down

0 comments on commit 57c3298

Please sign in to comment.