diff -Nru golang-github-mssola-user-agent-0.5.0/all_test.go golang-github-mssola-user-agent-0.5.1/all_test.go --- golang-github-mssola-user-agent-0.5.0/all_test.go 2018-11-20 16:08:45.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/all_test.go 2020-01-10 15:27:21.000000000 +0000 @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2018 Miquel Sabaté Solà +// Copyright (C) 2012-2019 Miquel Sabaté Solà // This file is licensed under the MIT license. // See the LICENSE file. @@ -35,6 +35,11 @@ expected: "Mozilla:5.0 Browser:Googlebot-2.1 Bot:true Mobile:true", }, { + title: "GoogleBotEmulateMozilla", + ua: "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36", + expected: "Mozilla:5.0 Browser:Googlebot-2.1 Bot:true Mobile:false", + }, + { title: "BingBot", ua: "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", expected: "Mozilla:5.0 Browser:bingbot-2.0 Bot:true Mobile:false", @@ -333,6 +338,31 @@ expected: "Platform:Windows OS:Windows 7 Localization:en Browser:Opera-9.80 Engine:Presto-2.9.168 Bot:false Mobile:false", }, + // Yandex Browser + { + title: "YandexBrowserLinux", + ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.99 YaBrowser/19.1.0.2494 (beta) Yowser/2.5 Safari/537.36", + expected: "Mozilla:5.0 Platform:X11 OS:Linux x86_64 Browser:YaBrowser-19.1.0.2494 Engine:AppleWebKit-537.36 Bot:false Mobile:false", + expectedOS: &OSInfo{"Linux x86_64", "Linux", ""}, + }, + + { + title: "YandexBrowserWindows", + ua: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 YaBrowser/17.3.1.840 Yowser/2.5 Safari/537.36", + expected: "Mozilla:5.0 Platform:Windows OS:Windows 7 Browser:YaBrowser-17.3.1.840 Engine:AppleWebKit-537.36 Bot:false Mobile:false", + }, + + { + title: "YandexBrowserAndroid", + ua: "Mozilla/5.0 (Linux; Android 4.4.4; GT-I9300I Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 YaBrowser/17.9.0.523.00 Mobile Safari/537.36", + expected: "Mozilla:5.0 Platform:Linux OS:Android 4.4.4 Browser:YaBrowser-17.9.0.523.00 Engine:AppleWebKit-537.36 Bot:false Mobile:true", + }, + + { + title: "YandexBrowserIOS", + ua: "Mozilla/5.0 (iPad; CPU OS 10_1_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 YaBrowser/16.11.1.716.11 Mobile/14B100 Safari/602.1", + expected: "Mozilla:5.0 Platform:iPad OS:CPU OS 10_1_1 like Mac OS X Browser:YaBrowser-16.11.1.716.11 Engine:AppleWebKit-602.1.50 Bot:false Mobile:true", + }, // Other { title: "Empty", @@ -467,6 +497,11 @@ expected: "Mozilla:5.0 Platform:Linux OS:Android 4.2.1 Browser:Chrome-18.0.1025.166 Engine:AppleWebKit-535.19 Bot:false Mobile:true", }, { + title: "Chrome for iOS", + ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 11_3_1 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) CriOS/67.0.3396.87 Mobile/15E302 Safari/604.1", + expected: "Mozilla:5.0 Platform:iPhone OS:CPU iPhone OS 11_3_1 like Mac OS X Browser:Chrome-67.0.3396.87 Engine:AppleWebKit-604.1.34 Bot:false Mobile:true", + }, + { title: "WebkitNoPlatform", ua: "Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13", expected: "Mozilla:5.0 Platform:en-us Localization:en-us Browser:Safari-3.1 Engine:AppleWebKit-525.13 Bot:false Mobile:false", @@ -501,6 +536,11 @@ ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36", expected: "Mozilla:5.0 Platform:X11 OS:Linux x86_64 Browser:Chromium-53.0.2785.143 Engine:AppleWebKit-537.36 Bot:false Mobile:false", }, + { + title: "Firefox for iOS", + ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4", + expected: "Mozilla:5.0 Platform:iPhone OS:CPU iPhone OS 8_3 like Mac OS X Browser:Firefox-1.0 Engine:AppleWebKit-600.1.4 Bot:false Mobile:true", + }, // Dalvik { @@ -534,6 +574,16 @@ ua: "Dalvik/1.6.0 (Linux; U; Android 4.0.4; W2430 Build/IMM76D)014; Profile/MIDP-2.1 Configuration/CLDC-1", expected: "Mozilla:5.0 Platform:Linux OS:Android 4.0.4 Bot:false Mobile:true", }, + { + title: "Samsung S5 Facebook App", + ua: "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.121 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/35.0.0.48.273;]", + expected: "Mozilla:5.0 Platform:Linux OS:Android 5.0 Localization:wv Browser:Android-4.0 Engine:AppleWebKit-537.36 Bot:false Mobile:true", + }, + { + title: "Facebook - No Browser Or OS", + ua: "[FBAN/FB4A;FBAV/16.0.0.20.15;FBBV/4061184;FBDM/{density=1.5,width=540,height=960};FBLC/en_US;FB_FW/2;FBCR/MY CELCOM;FBPN/com.facebook.katana;FBDV/Lenovo A850+;FBSV/4.2.2;FBOP/1;FBCA/armeabi-v7a:armeabi;]", + expected: "Bot:false Mobile:false", + }, } // Internal: beautify the UserAgent reference into a string so it can be diff -Nru golang-github-mssola-user-agent-0.5.0/bot.go golang-github-mssola-user-agent-0.5.1/bot.go --- golang-github-mssola-user-agent-0.5.0/bot.go 2018-11-20 16:08:45.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/bot.go 2020-01-10 15:27:21.000000000 +0000 @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2018 Miquel Sabaté Solà +// Copyright (C) 2014-2019 Miquel Sabaté Solà // This file is licensed under the MIT license. // See the LICENSE file. @@ -22,6 +22,8 @@ idx := 2 if len(comment) < 3 { idx = 0 + } else if len(comment) == 4 { + idx = 3 } // Pick the site. @@ -34,7 +36,7 @@ // This is a large comment, usually the name will be in the previous // field of the comment. - return strings.TrimSpace(comment[1]) + return strings.TrimSpace(comment[idx-1]) } return "" } diff -Nru golang-github-mssola-user-agent-0.5.0/browser.go golang-github-mssola-user-agent-0.5.1/browser.go --- golang-github-mssola-user-agent-0.5.0/browser.go 2018-11-20 16:08:45.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/browser.go 2020-01-10 15:27:21.000000000 +0000 @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2018 Miquel Sabaté Solà +// Copyright (C) 2012-2019 Miquel Sabaté Solà // This file is licensed under the MIT license. // See the LICENSE file. @@ -69,12 +69,28 @@ p.browser.Name = "Opera" p.browser.Version = sections[slen-1].version default: - if sections[sectionIndex].name == "Chrome" { - p.browser.Name = "Chrome" - } else if sections[sectionIndex].name == "Chromium" { - p.browser.Name = "Chromium" - } else { - p.browser.Name = "Safari" + switch sections[slen-3].name { + case "YaBrowser": + p.browser.Name = "YaBrowser" + p.browser.Version = sections[slen-3].version + default: + switch sections[sectionIndex].name { + case "Chrome", "CriOS": + p.browser.Name = "Chrome" + case "Chromium": + p.browser.Name = "Chromium" + case "FxiOS": + p.browser.Name = "Firefox" + default: + p.browser.Name = "Safari" + } + } + // It's possible the google-bot emulates these now + for _, comment := range engine.comment { + if len(comment) > 5 && strings.HasPrefix(comment, "Googlebot") { + p.undecided = true + break + } } } } else if engine.name == "Gecko" { @@ -127,13 +143,13 @@ } } -// Returns two strings. The first string is the name of the engine and the +// Engine returns two strings. The first string is the name of the engine and the // second one is the version of the engine. func (p *UserAgent) Engine() (string, string) { return p.browser.Engine, p.browser.EngineVersion } -// Returns two strings. The first string is the name of the browser and the +// Browser returns two strings. The first string is the name of the browser and the // second one is the version of the browser. func (p *UserAgent) Browser() (string, string) { return p.browser.Name, p.browser.Version diff -Nru golang-github-mssola-user-agent-0.5.0/CHANGELOG.md golang-github-mssola-user-agent-0.5.1/CHANGELOG.md --- golang-github-mssola-user-agent-0.5.0/CHANGELOG.md 2018-11-20 16:08:45.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/CHANGELOG.md 2020-01-10 15:27:21.000000000 +0000 @@ -1,5 +1,18 @@ # Changelog +## 0.5.1 + +- 00a868fa17e7 add Firefox for iOS +- 8c16c37f4e07 Add go.mod +- 7e313fc62553 Use CodeLingo to Address Further Issues +- 95b0c164394f Fix function comments based on best practices from Effective Go +- 1df9e04ee4f5 test: mobile Yandex Browser +- 6eb76c60b5e8 Add Yandex browser +- 8b3999083770 Updating license notice +- 82f141dea4a8 Detect Chrome for iOS correctly +- 5723c361ed97 Facebook App Handling +- 57c32981bd5f Add a new google bot user agent format + ## 0.5.0 ### Newly supported and improvements diff -Nru golang-github-mssola-user-agent-0.5.0/codelingo.yaml golang-github-mssola-user-agent-0.5.1/codelingo.yaml --- golang-github-mssola-user-agent-0.5.0/codelingo.yaml 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/codelingo.yaml 2020-01-10 15:27:21.000000000 +0000 @@ -0,0 +1,8 @@ +tenets: + - import: codelingo/effective-go/comment-first-word-as-subject + - import: codelingo/effective-go/avoid-annotations-in-comments + - import: codelingo/effective-go/underscores-in-name + - import: codelingo/go/golint + - import: codelingo/go/global-var + - import: codelingo/go/tested + - import: codelingo/lightning-network-daemon \ No newline at end of file diff -Nru golang-github-mssola-user-agent-0.5.0/debian/changelog golang-github-mssola-user-agent-0.5.1/debian/changelog --- golang-github-mssola-user-agent-0.5.0/debian/changelog 2019-12-25 21:08:09.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/debian/changelog 2020-01-23 07:56:07.000000000 +0000 @@ -1,3 +1,9 @@ +golang-github-mssola-user-agent (0.5.1-1) unstable; urgency=medium + + * New upstream release. + + -- Dmitry Smirnov Thu, 23 Jan 2020 18:56:07 +1100 + golang-github-mssola-user-agent (0.5.0-1) unstable; urgency=medium * New upstream release diff -Nru golang-github-mssola-user-agent-0.5.0/debian/copyright golang-github-mssola-user-agent-0.5.1/debian/copyright --- golang-github-mssola-user-agent-0.5.0/debian/copyright 2019-12-25 21:08:09.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/debian/copyright 2020-01-23 07:56:07.000000000 +0000 @@ -5,7 +5,7 @@ Godeps/_workspace Files: * -Copyright: 2012-2018 Miquel Sabaté Solà +Copyright: 2012-2019 Miquel Sabaté Solà License: Expat Files: debian/* diff -Nru golang-github-mssola-user-agent-0.5.0/go.mod golang-github-mssola-user-agent-0.5.1/go.mod --- golang-github-mssola-user-agent-0.5.0/go.mod 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/go.mod 2020-01-10 15:27:21.000000000 +0000 @@ -0,0 +1,3 @@ +module github.com/mssola/user_agent + +go 1.13 diff -Nru golang-github-mssola-user-agent-0.5.0/LICENSE golang-github-mssola-user-agent-0.5.1/LICENSE --- golang-github-mssola-user-agent-0.5.0/LICENSE 2018-11-20 16:08:45.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/LICENSE 2020-01-10 15:27:21.000000000 +0000 @@ -1,4 +1,4 @@ -Copyright (c) 2012-2018 Miquel Sabaté Solà +Copyright (c) 2012-2019 Miquel Sabaté Solà Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff -Nru golang-github-mssola-user-agent-0.5.0/operating_systems.go golang-github-mssola-user-agent-0.5.1/operating_systems.go --- golang-github-mssola-user-agent-0.5.0/operating_systems.go 2018-11-20 16:08:45.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/operating_systems.go 2020-01-10 15:27:21.000000000 +0000 @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2018 Miquel Sabaté Solà +// Copyright (C) 2012-2019 Miquel Sabaté Solà // This file is licensed under the MIT license. // See the LICENSE file. @@ -282,17 +282,17 @@ } } -// Returns a string containing the platform.. +// Platform returns a string containing the platform.. func (p *UserAgent) Platform() string { return p.platform } -// Returns a string containing the name of the Operating System. +// OS returns a string containing the name of the Operating System. func (p *UserAgent) OS() string { return p.os } -// Returns a string containing the localization. +// Localization returns a string containing the localization. func (p *UserAgent) Localization() string { return p.localization } @@ -325,7 +325,7 @@ return name, version } -// Returns combined information for the operating system. +// OSInfo returns combined information for the operating system. func (p *UserAgent) OSInfo() OSInfo { // Special case for iPhone weirdness os := strings.Replace(p.os, "like Mac OS X", "", 1) diff -Nru golang-github-mssola-user-agent-0.5.0/README.md golang-github-mssola-user-agent-0.5.1/README.md --- golang-github-mssola-user-agent-0.5.0/README.md 2018-11-20 16:08:45.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/README.md 2020-01-10 15:27:21.000000000 +0000 @@ -48,4 +48,4 @@ } ~~~ -Copyright © 2012-2018 Miquel Sabaté Solà, released under the MIT License. +Copyright © 2012-2019 Miquel Sabaté Solà, released under the MIT License. diff -Nru golang-github-mssola-user-agent-0.5.0/user_agent.go golang-github-mssola-user-agent-0.5.1/user_agent.go --- golang-github-mssola-user-agent-0.5.0/user_agent.go 2018-11-20 16:08:45.000000000 +0000 +++ golang-github-mssola-user-agent-0.5.1/user_agent.go 2020-01-10 15:27:21.000000000 +0000 @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2018 Miquel Sabaté Solà +// Copyright (C) 2012-2019 Miquel Sabaté Solà // This file is licensed under the MIT license. // See the LICENSE file. @@ -85,15 +85,27 @@ // Returns a section containing the information that we could extract // from the last parsed section. func parseSection(ua string, index *int) (s section) { - buffer := readUntil(ua, index, ' ', false) + var buffer []byte + + // Check for empty products + if *index < len(ua) && ua[*index] != '(' && ua[*index] != '[' { + buffer = readUntil(ua, index, ' ', false) + s.name, s.version = parseProduct(buffer) + } - s.name, s.version = parseProduct(buffer) if *index < len(ua) && ua[*index] == '(' { *index++ buffer = readUntil(ua, index, ')', true) s.comment = strings.Split(string(buffer), "; ") *index++ } + + // Discards any trailing data within square brackets + if *index < len(ua) && ua[*index] == '[' { + *index++ + buffer = readUntil(ua, index, ']', true) + *index++ + } return s } @@ -152,23 +164,23 @@ } } -// Returns the mozilla version (it's how the User Agent string begins: +// Mozilla returns the mozilla version (it's how the User Agent string begins: // "Mozilla/5.0 ...", unless we're dealing with Opera, of course). func (p *UserAgent) Mozilla() string { return p.mozilla } -// Returns true if it's a bot, false otherwise. +// Bot returns true if it's a bot, false otherwise. func (p *UserAgent) Bot() bool { return p.bot } -// Returns true if it's a mobile device, false otherwise. +// Mobile returns true if it's a mobile device, false otherwise. func (p *UserAgent) Mobile() bool { return p.mobile } -// Returns the original given user agent. +// UA returns the original given user agent. func (p *UserAgent) UA() string { return p.ua }