summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mssola/user_agent/browser.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/mssola/user_agent/browser.go')
-rw-r--r--vendor/github.com/mssola/user_agent/browser.go40
1 files changed, 30 insertions, 10 deletions
diff --git a/vendor/github.com/mssola/user_agent/browser.go b/vendor/github.com/mssola/user_agent/browser.go
index 74fb931ef..fbed92176 100644
--- a/vendor/github.com/mssola/user_agent/browser.go
+++ b/vendor/github.com/mssola/user_agent/browser.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2014 Miquel Sabaté Solà <mikisabate@gmail.com>
+// Copyright (C) 2012-2017 Miquel Sabaté Solà <mikisabate@gmail.com>
// This file is licensed under the MIT license.
// See the LICENSE file.
@@ -9,6 +9,8 @@ import (
"strings"
)
+var ie11Regexp = regexp.MustCompile("^rv:(.+)$")
+
// A struct containing all the information that we might be
// interested from the browser.
type Browser struct {
@@ -34,27 +36,46 @@ func (p *UserAgent) detectBrowser(sections []section) {
slen := len(sections)
if sections[0].name == "Opera" {
- p.mozilla = ""
p.browser.Name = "Opera"
p.browser.Version = sections[0].version
p.browser.Engine = "Presto"
if slen > 1 {
p.browser.EngineVersion = sections[1].version
}
+ } else if sections[0].name == "Dalvik" {
+ // When Dalvik VM is in use, there is no browser info attached to ua.
+ // Although browser is still a Mozilla/5.0 compatible.
+ p.mozilla = "5.0"
} else if slen > 1 {
engine := sections[1]
p.browser.Engine = engine.name
p.browser.EngineVersion = engine.version
if slen > 2 {
- p.browser.Version = sections[2].version
+ sectionIndex := 2
+ // The version after the engine comment is empty on e.g. Ubuntu
+ // platforms so if this is the case, let's use the next in line.
+ if sections[2].version == "" && slen > 3 {
+ sectionIndex = 3
+ }
+ p.browser.Version = sections[sectionIndex].version
if engine.name == "AppleWebKit" {
- if sections[slen-1].name == "OPR" {
+ switch sections[slen-1].name {
+ case "Edge":
+ p.browser.Name = "Edge"
+ p.browser.Version = sections[slen-1].version
+ p.browser.Engine = "EdgeHTML"
+ p.browser.EngineVersion = ""
+ case "OPR":
p.browser.Name = "Opera"
p.browser.Version = sections[slen-1].version
- } else if sections[2].name == "Chrome" {
- p.browser.Name = "Chrome"
- } else {
- p.browser.Name = "Safari"
+ 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"
+ }
}
} else if engine.name == "Gecko" {
name := sections[2].name
@@ -67,9 +88,8 @@ func (p *UserAgent) detectBrowser(sections []section) {
// This is the new user agent from Internet Explorer 11.
p.browser.Engine = "Trident"
p.browser.Name = "Internet Explorer"
- reg, _ := regexp.Compile("^rv:(.+)$")
for _, c := range sections[0].comment {
- version := reg.FindStringSubmatch(c)
+ version := ie11Regexp.FindStringSubmatch(c)
if len(version) > 0 {
p.browser.Version = version[1]
return