Skip to content

Commit

Permalink
Recognize bot as higher priority. (avct#38)
Browse files Browse the repository at this point in the history
It should have more sense, because bots mimic the real browsers and contains both kind of attributes: bot and real browser. Previous implementation didn't try to recognize a bot if there is browser attributes in the ua string.

The bug that reproduces the problem is covered by the unit tests.

fixed CR comments

fix CR comments

fixed CR comments

add Amazon Fire Stick device detection as TV (avct#36)

https://deviceatlas.com/blog/list-smart-tv-user-agent-strings

merge

fix CR comments
  • Loading branch information
Dorokhov authored and ryanslade committed Aug 17, 2018
1 parent 5627c17 commit dc0ec4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func (u *UserAgent) evalBrowserName(ua string) bool {

if strings.Contains(ua, "applewebkit") {
switch {
case strings.Contains(ua, "googlebot"):
u.Browser.Name = BrowserGoogleBot

case strings.Contains(ua, "opr/") || strings.Contains(ua, "opios/"):
u.Browser.Name = BrowserOpera

Expand Down Expand Up @@ -189,4 +192,4 @@ func (u *UserAgent) evalBrowserVersion(ua string) {
case BrowserSpotify:
_ = u.Browser.Version.findVersionNumber(ua, "spotify/")
}
}
}
9 changes: 7 additions & 2 deletions uasurfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,13 @@ var testUAVars = []struct {
UserAgent{
Browser{BrowserYahooBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}},

// {"Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
// BrowserBot, Version{0,0,0}}, OS{PlatformBot, OSBot, Version{6,0,0}}, DeviceComputer}},
{"{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)}, ua: &{Browser:{Name:BrowserGoogleBot Version:{Major:0 Minor:0 Patch:0}} OS:{Platform:PlatformBot Name:OSBot Version:{Major:6 Minor:0 Patch:1}} DeviceType:DeviceComputer}",
UserAgent{
Browser{BrowserGoogleBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{6, 0, 1}}, DeviceComputer}},

{"Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
UserAgent{
Browser{BrowserGoogleBot, Version{0,0,0}}, OS{PlatformBot, OSBot, Version{6,0,0}}, DeviceComputer}},

{"mozilla/5.0 (unknown; linux x86_64) applewebkit/538.1 (khtml, like gecko) phantomjs/2.1.1 safari/538.1",
UserAgent{
Expand Down

0 comments on commit dc0ec4f

Please sign in to comment.