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

Commit b1b4c4a

Browse files
authored
Merge pull request #44 from araddon/new_bot
Add a new google bot user agent format
2 parents 6efee03 + 57c3298 commit b1b4c4a

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
@@ -83,6 +83,13 @@ func (p *UserAgent) detectBrowser(sections []section) {
8383
p.browser.Name = "Safari"
8484
}
8585
}
86+
// Its possible the google-bot emulates these now
87+
for _, comment := range engine.comment {
88+
if len(comment) > 5 && strings.HasPrefix(comment, "Googlebot") {
89+
p.undecided = true
90+
break
91+
}
92+
}
8693
}
8794
} else if engine.name == "Gecko" {
8895
name := sections[2].name

0 commit comments

Comments
 (0)