Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

Commit 57c3298

Browse files
author
Aaron Raddon
committed
Add a new google bot user agent format
1 parent d7bd3b0 commit 57c3298

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

all_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ var uastrings = []struct {
3434
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)",
3535
expected: "Mozilla:5.0 Browser:Googlebot-2.1 Bot:true Mobile:true",
3636
},
37+
{
38+
title: "GoogleBotEmulateMozilla",
39+
ua: "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36",
40+
expected: "Mozilla:5.0 Browser:Googlebot-2.1 Bot:true Mobile:false",
41+
},
3742
{
3843
title: "BingBot",
3944
ua: "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",

bot.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func getFromSite(comment []string) string {
2222
idx := 2
2323
if len(comment) < 3 {
2424
idx = 0
25+
} else if len(comment) == 4 {
26+
idx = 3
2527
}
2628

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

3537
// This is a large comment, usually the name will be in the previous
3638
// field of the comment.
37-
return strings.TrimSpace(comment[1])
39+
return strings.TrimSpace(comment[idx-1])
3840
}
3941
return ""
4042
}

browser.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ func (p *UserAgent) detectBrowser(sections []section) {
7676
} else {
7777
p.browser.Name = "Safari"
7878
}
79+
// Its possible the google-bot emulates these now
80+
for _, comment := range engine.comment {
81+
if len(comment) > 5 && strings.HasPrefix(comment, "Googlebot") {
82+
p.undecided = true
83+
break
84+
}
85+
}
7986
}
8087
} else if engine.name == "Gecko" {
8188
name := sections[2].name

0 commit comments

Comments
 (0)