From 359628f1779dd429a749ad88271114e1e6d59a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Mileusni=C4=87?= Date: Thu, 28 Jul 2022 20:26:39 +0200 Subject: [PATCH] HuaweiBrowser check, ChromeOS renamed --- ua.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ua.go b/ua.go index e408de6..d643550 100644 --- a/ua.go +++ b/ua.go @@ -1,4 +1,4 @@ -package ua +package useragent import ( "bytes" @@ -37,7 +37,7 @@ const ( MacOS = "macOS" IOS = "iOS" Linux = "Linux" - ChromeOS = "CrOS" + ChromeOS = "ChromeOS" Opera = "Opera" OperaMini = "Opera Mini" @@ -53,6 +53,7 @@ const ( Twitterbot = "Twitterbot" FacebookExternalHit = "facebookexternalhit" Applebot = "Applebot" + Bingbot = "Bingbot" ) // Parse user agent string returning UserAgent struct @@ -119,9 +120,8 @@ func Parse(userAgent string) UserAgent { case tokens.exists("CrOS"): ua.OS = ChromeOS - ua.OSVersion = tokens.get(ChromeOS) + ua.OSVersion = tokens.get("CrOS") ua.Desktop = true - } // for s, val := range sys { @@ -211,7 +211,7 @@ func Parse(userAgent string) UserAgent { ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari") case tokens.get("bingbot") != "": - ua.Name = "Bingbot" + ua.Name = Bingbot ua.Version = tokens.get("bingbot") ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari") @@ -225,6 +225,11 @@ func Parse(userAgent string) UserAgent { ua.Version = tokens.get("SamsungBrowser") 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 case tokens.exists(Chrome) && tokens.exists(Safari): name := tokens.findBestMatch(true) @@ -456,7 +461,7 @@ func (p properties) findBestMatch(withVerOnly bool) string { for i := 0; i < n; i++ { for _, prop := range p.list { 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: if i == 0 { if prop.Value != "" { // in first check, only return keys with value