Merge branch 'pr/wolfeidau/40'
This commit is contained in:
@@ -159,6 +159,13 @@ func Parse(userAgent string) UserAgent {
|
|||||||
}
|
}
|
||||||
ua.Bot = true
|
ua.Bot = true
|
||||||
|
|
||||||
|
case tokens.existsAny("Bytespider", "Bytespider"):
|
||||||
|
if name := tokens.findBestMatch(false); name != "" {
|
||||||
|
ua.Name = name
|
||||||
|
ua.OS = ""
|
||||||
|
}
|
||||||
|
ua.Bot = true
|
||||||
|
|
||||||
case tokens.exists(Applebot):
|
case tokens.exists(Applebot):
|
||||||
ua.Name = Applebot
|
ua.Name = Applebot
|
||||||
ua.Version = tokens.get(Applebot)
|
ua.Version = tokens.get(Applebot)
|
||||||
@@ -370,14 +377,12 @@ func Parse(userAgent string) UserAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if not already bot, check some popular bots and whether URL is set
|
// if not already bot, check some popular bots and whether URL is set
|
||||||
if !ua.Bot {
|
|
||||||
ua.Bot = ua.URL != ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ua.Bot {
|
if !ua.Bot {
|
||||||
switch ua.Name {
|
switch ua.Name {
|
||||||
case Twitterbot, FacebookExternalHit:
|
case Twitterbot, FacebookExternalHit, "facebookcatalog":
|
||||||
ua.Bot = true
|
ua.Bot = true
|
||||||
|
default:
|
||||||
|
ua.Bot = ua.URL != ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -91,6 +91,8 @@ var testTable = [][]string{
|
|||||||
{"Mozilla/5.0 (compatible; Yahoo Ad monitoring; https://help.yahoo.com/kb/yahoo-ad-monitoring-SLN24857.html) cnv.aws-prod---sieve.hlfs-rest_client/1681346790-0", "Yahoo Ad monitoring", "", "bot", ""},
|
{"Mozilla/5.0 (compatible; Yahoo Ad monitoring; https://help.yahoo.com/kb/yahoo-ad-monitoring-SLN24857.html) cnv.aws-prod---sieve.hlfs-rest_client/1681346790-0", "Yahoo Ad monitoring", "", "bot", ""},
|
||||||
{"GoogleProber", "GoogleProber", "", "bot", ""},
|
{"GoogleProber", "GoogleProber", "", "bot", ""},
|
||||||
{"GoogleProducer; (+http://goo.gl/7y4SX)", "GoogleProducer", "", "bot", ""},
|
{"GoogleProducer; (+http://goo.gl/7y4SX)", "GoogleProducer", "", "bot", ""},
|
||||||
|
{"Mozilla/5.0 (compatible; Bytespider; spider-feedback@bytedance.com) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.0.0 Safari/537.36", "Bytespider", "", "bot", ""},
|
||||||
|
{"Mozilla/5.0 (Linux; Android 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Mobile Safari/537.36 (compatible; Bytespider; spider-feedback@bytedance.com)", "Bytespider", "", "bot", ""},
|
||||||
|
|
||||||
// Google ads bots
|
// Google ads bots
|
||||||
{"Mozilla/5.0 (Linux; Android 4.0.0; Galaxy Nexus Build/IMM76B) AppleWebKit/537.36 (KHTML, like Gecko; Mediapartners-Google) Chrome/104.0.0.0 Mobile Safari/537.36", ua.GoogleAdsBot, "", "bot", ua.Android},
|
{"Mozilla/5.0 (Linux; Android 4.0.0; Galaxy Nexus Build/IMM76B) AppleWebKit/537.36 (KHTML, like Gecko; Mediapartners-Google) Chrome/104.0.0.0 Mobile Safari/537.36", ua.GoogleAdsBot, "", "bot", ua.Android},
|
||||||
@@ -198,6 +200,10 @@ func TestParse(t *testing.T) {
|
|||||||
t.Error("\n", ua.String, "should be tablet")
|
t.Error("\n", ua.String, "should be tablet")
|
||||||
fmt.Printf("%+v", ua)
|
fmt.Printf("%+v", ua)
|
||||||
}
|
}
|
||||||
|
if test[3] == "bot" && !ua.Bot {
|
||||||
|
t.Error("\n", ua.String, "should be bot")
|
||||||
|
fmt.Printf("%+v", ua)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(test) > 4 && test[4] != ua.OS {
|
if len(test) > 4 && test[4] != ua.OS {
|
||||||
@@ -224,7 +230,8 @@ func BenchmarkUserAgent(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSingle(t *testing.T) {
|
func TestSingle(t *testing.T) {
|
||||||
agent := ua.Parse("SonyEricssonK310iv/R4DA Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Link/6.3.1.13.0")
|
//agent := ua.Parse("SonyEricssonK310iv/R4DA Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Link/6.3.1.13.0")
|
||||||
|
agent := ua.Parse("Mozilla/5.0 (Linux; Android 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Mobile Safari/537.36 (compatible; Bytespider; spider-feedback@bytedance.com)")
|
||||||
fmt.Printf("\n%+v\n", agent)
|
fmt.Printf("\n%+v\n", agent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user