Skip to content

Commit 3ca2319

Browse files
committed
Improve OS detection: fix Linux arch mistakenly detected as version
1 parent 9e64f34 commit 3ca2319

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Diff for: src/main/ua-parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@
965965
/(mageia|vectorlinux)[; ]/i, // Mageia/VectorLinux
966966
/([kxln]?ubuntu|debian|suse|opensuse|gentoo|arch(?= linux)|slackware|fedora|mandriva|centos|pclinuxos|red ?hat|zenwalk|linpus|raspbian|plan 9|minix|risc os|contiki|deepin|manjaro|elementary os|sabayon|linspire)(?: gnu\/linux)?(?: enterprise)?(?:[- ]linux)?(?:-gnu)?[-\/ ]?(?!chrom|package)([-\w\.]*)/i,
967967
// Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware/Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus/Raspbian/Plan9/Minix/RISCOS/Contiki/Deepin/Manjaro/elementary/Sabayon/Linspire
968-
/(hurd|linux) ?([\w\.]*)/i, // Hurd/Linux
968+
/(hurd|linux)(?: arm\w*| x86\w*| ?)([\w\.]*)/i, // Hurd/Linux
969969
/(gnu) ?([\w\.]*)/i, // GNU
970970
/\b([-frentopcghs]{0,5}bsd|dragonfly)[\/ ]?(?!amd|[ix346]{1,2}86)([\w\.]*)/i, // FreeBSD/NetBSD/OpenBSD/PC-BSD/GhostBSD/DragonFly
971971
/(haiku) (\w+)/i // Haiku

Diff for: test/data/ua/os/linux.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
"expect" :
66
{
77
"name" : "Linux",
8-
"version" : "x86_64"
8+
"version" : "undefined"
9+
}
10+
},
11+
{
12+
"desc" : "Linux",
13+
"ua" : "Mozilla/5.0 (X11; U; Linux armv61; en-US; rv:1.9.1b2pre) Gecko/20081015 Fennec/1.0a1",
14+
"expect" :
15+
{
16+
"name" : "Linux",
17+
"version" : "undefined"
918
}
1019
}
1120
]

Diff for: test/unit/ua-ch.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('Map UA-CH headers', () => {
6868
assert.strictEqual(uap.engine.name, 'Blink');
6969
assert.strictEqual(uap.engine.version, '110.0.0.0');
7070
assert.strictEqual(uap.os.name, "Linux");
71-
assert.strictEqual(uap.os.version, "x86_64");
71+
assert.strictEqual(uap.os.version, undefined);
7272
});
7373

7474
it('Fallback to user-agent header when using `withClientHints()` but found no client hints-related headers', () => {
@@ -90,7 +90,7 @@ describe('Map UA-CH headers', () => {
9090
assert.strictEqual(uap.engine.name, 'Blink');
9191
assert.strictEqual(uap.engine.version, '110.0.0.0');
9292
assert.strictEqual(uap.os.name, "Linux");
93-
assert.strictEqual(uap.os.version, "x86_64");
93+
assert.strictEqual(uap.os.version, undefined);
9494
});
9595

9696
it('Can detect Apple silicon from client hints data', () => {

0 commit comments

Comments
 (0)