Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

Commit 6e7843e

Browse files
committed
Add Chromium support and Ubuntu specific tests
This commit adds support for the Chromium user agent string and adds user agent tests for the latest version of all major browsers available on Ubuntu. Fixes: - Ignore revision field for localization (e.g. rv:50.0) - Ignore browser name parameter without version (e.g. "Ubuntu") Fixes #27
1 parent 8e786bc commit 6e7843e

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

all_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ var uastrings = []struct {
173173
ua: "Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20100101 Firefox/17.0",
174174
expected: "Mozilla:5.0 Platform:X11 OS:Linux x86_64 Browser:Firefox-17.0 Engine:Gecko-20100101 Bot:false Mobile:false",
175175
},
176+
{
177+
title: "FirefoxLinux - Ubuntu V50",
178+
ua: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0",
179+
expected: "Mozilla:5.0 Platform:X11 OS:Ubuntu Browser:Firefox-50.0 Engine:Gecko-20100101 Bot:false Mobile:false",
180+
},
176181
{
177182
title: "FirefoxWin",
178183
ua: "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14",
@@ -265,6 +270,11 @@ var uastrings = []struct {
265270
ua: "Opera/9.80 (X11; Linux x86_64) Presto/2.12.388 Version/12.10",
266271
expected: "Platform:X11 OS:Linux x86_64 Browser:Opera-9.80 Engine:Presto-2.12.388 Bot:false Mobile:false",
267272
},
273+
{
274+
title: "OperaLinux - Ubuntu V41",
275+
ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 OPR/41.0.2353.69",
276+
expected: "Mozilla:5.0 Platform:X11 OS:Linux x86_64 Browser:Opera-41.0.2353.69 Engine:AppleWebKit-537.36 Bot:false Mobile:false",
277+
},
268278
{
269279
title: "OperaAndroid",
270280
ua: "Opera/9.80 (Android 4.2.1; Linux; Opera Mobi/ADR-1212030829) Presto/2.11.355 Version/12.10",
@@ -329,6 +339,11 @@ var uastrings = []struct {
329339
ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
330340
expected: "Mozilla:5.0 Platform:X11 OS:Linux x86_64 Browser:Chrome-23.0.1271.97 Engine:AppleWebKit-537.11 Bot:false Mobile:false",
331341
},
342+
{
343+
title: "ChromeLinux - Ubuntu V55",
344+
ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36",
345+
expected: "Mozilla:5.0 Platform:X11 OS:Linux x86_64 Browser:Chrome-55.0.2883.75 Engine:AppleWebKit-537.36 Bot:false Mobile:false",
346+
},
332347
{
333348
title: "ChromeWin7",
334349
ua: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19",
@@ -429,6 +444,16 @@ var uastrings = []struct {
429444
ua: "Mozilla/5.0 (SymbianOS/9.1; U; [en-us]) AppleWebKit/413 (KHTML, like Gecko) Safari/413",
430445
expected: "Mozilla:5.0 Platform:Symbian OS:SymbianOS/9.1 Browser:Symbian-413 Engine:AppleWebKit-413 Bot:false Mobile:true",
431446
},
447+
{
448+
title: "Chromium - Ubuntu V49",
449+
ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108 Safari/537.36",
450+
expected: "Mozilla:5.0 Platform:X11 OS:Linux x86_64 Browser:Chromium-49.0.2623.108 Engine:AppleWebKit-537.36 Bot:false Mobile:false",
451+
},
452+
{
453+
title: "Chromium - Ubuntu V55",
454+
ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36",
455+
expected: "Mozilla:5.0 Platform:X11 OS:Linux x86_64 Browser:Chromium-53.0.2785.143 Engine:AppleWebKit-537.36 Bot:false Mobile:false",
456+
},
432457

433458
// Dalvik
434459
{

browser.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ func (p *UserAgent) detectBrowser(sections []section) {
5151
p.browser.Engine = engine.name
5252
p.browser.EngineVersion = engine.version
5353
if slen > 2 {
54-
p.browser.Version = sections[2].version
54+
sectionIndex := 2
55+
// The version after the engine comment is empty on e.g. Ubuntu
56+
// platforms so if this is the case, let's use the next in line.
57+
if sections[2].version == "" && slen > 3 {
58+
sectionIndex = 3
59+
}
60+
p.browser.Version = sections[sectionIndex].version
5561
if engine.name == "AppleWebKit" {
5662
switch sections[slen-1].name {
5763
case "Edge":
@@ -63,8 +69,10 @@ func (p *UserAgent) detectBrowser(sections []section) {
6369
p.browser.Name = "Opera"
6470
p.browser.Version = sections[slen-1].version
6571
default:
66-
if sections[2].name == "Chrome" {
72+
if sections[sectionIndex].name == "Chrome" {
6773
p.browser.Name = "Chrome"
74+
} else if sections[sectionIndex].name == "Chromium" {
75+
p.browser.Name = "Chromium"
6876
} else {
6977
p.browser.Name = "Safari"
7078
}

operating_systems.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ func gecko(p *UserAgent, comment []string) {
126126
}
127127
}
128128
}
129-
if len(comment) > 3 {
129+
// Only parse 4th comment as localization if it doesn't start with rv:.
130+
// For example Firefox on Ubuntu contains "rv:XX.X" in this field.
131+
if len(comment) > 3 && !strings.HasPrefix(comment[3], "rv:") {
130132
p.localization = comment[3]
131133
}
132134
}

0 commit comments

Comments
 (0)