2
0

HuaweiBrowser check, ChromeOS renamed

This commit is contained in:
Miloš Mileusnić
2022-07-28 20:26:39 +02:00
parent 413d85e15e
commit 359628f177
+11 -6
View File
@@ -1,4 +1,4 @@
package ua package useragent
import ( import (
"bytes" "bytes"
@@ -37,7 +37,7 @@ const (
MacOS = "macOS" MacOS = "macOS"
IOS = "iOS" IOS = "iOS"
Linux = "Linux" Linux = "Linux"
ChromeOS = "CrOS" ChromeOS = "ChromeOS"
Opera = "Opera" Opera = "Opera"
OperaMini = "Opera Mini" OperaMini = "Opera Mini"
@@ -53,6 +53,7 @@ const (
Twitterbot = "Twitterbot" Twitterbot = "Twitterbot"
FacebookExternalHit = "facebookexternalhit" FacebookExternalHit = "facebookexternalhit"
Applebot = "Applebot" Applebot = "Applebot"
Bingbot = "Bingbot"
) )
// Parse user agent string returning UserAgent struct // Parse user agent string returning UserAgent struct
@@ -119,9 +120,8 @@ func Parse(userAgent string) UserAgent {
case tokens.exists("CrOS"): case tokens.exists("CrOS"):
ua.OS = ChromeOS ua.OS = ChromeOS
ua.OSVersion = tokens.get(ChromeOS) ua.OSVersion = tokens.get("CrOS")
ua.Desktop = true ua.Desktop = true
} }
// for s, val := range sys { // for s, val := range sys {
@@ -211,7 +211,7 @@ func Parse(userAgent string) UserAgent {
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari") ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
case tokens.get("bingbot") != "": case tokens.get("bingbot") != "":
ua.Name = "Bingbot" ua.Name = Bingbot
ua.Version = tokens.get("bingbot") ua.Version = tokens.get("bingbot")
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari") ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
@@ -225,6 +225,11 @@ func Parse(userAgent string) UserAgent {
ua.Version = tokens.get("SamsungBrowser") ua.Version = tokens.get("SamsungBrowser")
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari") ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
case tokens.get("HuaweiBrowser") != "":
ua.Name = "Huawei Browser"
ua.Version = tokens.get("HuaweiBrowser")
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
// if chrome and Safari defined, find any other token sent descr // if chrome and Safari defined, find any other token sent descr
case tokens.exists(Chrome) && tokens.exists(Safari): case tokens.exists(Chrome) && tokens.exists(Safari):
name := tokens.findBestMatch(true) name := tokens.findBestMatch(true)
@@ -456,7 +461,7 @@ func (p properties) findBestMatch(withVerOnly bool) string {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
for _, prop := range p.list { for _, prop := range p.list {
switch prop.Key { switch prop.Key {
case Chrome, Firefox, Safari, "Version", "Mobile", "Mobile Safari", "Mozilla", "AppleWebKit", "Windows NT", "Windows Phone OS", Android, "Macintosh", Linux, "GSA", ChromeOS: case Chrome, Firefox, Safari, "Version", "Mobile", "Mobile Safari", "Mozilla", "AppleWebKit", "Windows NT", "Windows Phone OS", Android, "Macintosh", Linux, "GSA", "CrOS":
default: default:
if i == 0 { if i == 0 {
if prop.Value != "" { // in first check, only return keys with value if prop.Value != "" { // in first check, only return keys with value