Merge pull request #9 from tanrachel/master
This commit is contained in:
@@ -37,6 +37,7 @@ const (
|
||||
MacOS = "macOS"
|
||||
IOS = "iOS"
|
||||
Linux = "Linux"
|
||||
ChromeOS = "CrOS"
|
||||
|
||||
Opera = "Opera"
|
||||
OperaMini = "Opera Mini"
|
||||
@@ -115,6 +116,11 @@ func Parse(userAgent string) UserAgent {
|
||||
ua.OSVersion = tokens[Linux]
|
||||
ua.Desktop = true
|
||||
|
||||
case tokens.exists("CrOS"):
|
||||
ua.OS = ChromeOS
|
||||
ua.OSVersion = tokens[ChromeOS]
|
||||
ua.Desktop = true
|
||||
|
||||
}
|
||||
|
||||
// for s, val := range sys {
|
||||
@@ -359,6 +365,9 @@ func checkVer(s string) (name, v string) {
|
||||
switch s[:i] {
|
||||
case "Linux", "Windows NT", "Windows Phone OS", "MSIE", "Android":
|
||||
return s[:i], s[i+1:]
|
||||
case "CrOS x86_64", "CrOS aarch64" :
|
||||
j := strings.LastIndex(s[:i]," ")
|
||||
return s[:j],s[j+1:i]
|
||||
default:
|
||||
return s, ""
|
||||
}
|
||||
@@ -414,7 +423,7 @@ func (p properties) findBestMatch(withVerOnly bool) string {
|
||||
for i := 0; i < n; i++ {
|
||||
for k, v := range p {
|
||||
switch k {
|
||||
case Chrome, Firefox, Safari, "Version", "Mobile", "Mobile Safari", "Mozilla", "AppleWebKit", "Windows NT", "Windows Phone OS", Android, "Macintosh", Linux, "GSA":
|
||||
case Chrome, Firefox, Safari, "Version", "Mobile", "Mobile Safari", "Mozilla", "AppleWebKit", "Windows NT", "Windows Phone OS", Android, "Macintosh", Linux, "GSA", ChromeOS:
|
||||
default:
|
||||
if i == 0 {
|
||||
if v != "" { // in first check, only return keys with value
|
||||
|
||||
@@ -75,6 +75,7 @@ func TestParse(t *testing.T) {
|
||||
{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36", ua.Chrome, "87.0.4280.141", "desktop", ua.MacOS},
|
||||
|
||||
// other
|
||||
{"Mozilla/5.0 (X11; CrOS x86_64 14150.74.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.114 Safari/537.36",ua.Chrome, "94.0.4606.114", "desktop", ua.ChromeOS},
|
||||
{"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 Google (+https://developers.google.com/+/web/snippet/)", ua.Chrome, "56.0.2924.87", "bot", ua.Linux}, // Google+ fetch
|
||||
|
||||
// tools
|
||||
|
||||
Reference in New Issue
Block a user