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 (
"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