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

Commit 0319fcf

Browse files
committed
bot: check for in user agent
1 parent ea7cf3c commit 0319fcf

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

bot.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ func (p *UserAgent) fixOther(sections []section) {
7575
}
7676
}
7777

78+
var botRegex = regexp.MustCompile("(?i)(bot|crawler|sp(i|y)der|search|worm|fetch|nutch)")
79+
7880
// Check if we're dealing with a bot or with some weird browser. If that is the
7981
// case, the receiver will be modified accordingly.
8082
func (p *UserAgent) checkBot(sections []section) {
@@ -83,9 +85,8 @@ func (p *UserAgent) checkBot(sections []section) {
8385
if len(sections) == 1 && sections[0].name != "Mozilla" {
8486
p.mozilla = ""
8587

86-
// Check whether the name has some suspicious "bot" in his name.
87-
reg, _ := regexp.Compile("(?i)bot")
88-
if reg.Match([]byte(sections[0].name)) {
88+
// Check whether the name has some suspicious "bot" or "crawler" in his name.
89+
if botRegex.Match([]byte(sections[0].name)) {
8990
p.setSimple(sections[0].name, "", true)
9091
return
9192
}

0 commit comments

Comments
 (0)