Skip to content

Commit a3285e1

Browse files
committed
Added test case in order to reproduce issue #10 and relative fix
1 parent 0be37bc commit a3285e1

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"max-len": [
1515
1,
1616
120
17-
]
17+
],
18+
"no-console":"warn"
1819
}
1920
}

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
{
9+
"type": "node",
10+
"request": "launch",
11+
"name": "Launch Program",
12+
"program": "${workspaceFolder}/src/Parser.js",
13+
"runtimeExecutable": "/Users/simonemariotti/.nvm/versions/node/v8.6.0/bin/node"
14+
}
15+
]
16+
}

src/data/DeviceModels.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,18 @@ class DeviceModels {
197197
if (DeviceModels.hasMatch(v, model)) {
198198
if (v) {
199199
if (v.endsWith('!!')) {
200+
if (!list[v]) {
201+
if (!list[originalV]) {
202+
if (list[DeviceModels.getKey(v)]) {
203+
v = DeviceModels.getKey(v);
204+
} else if (list[DeviceModels.getKey(originalV)]) {
205+
v = DeviceModels.getKey(originalV);
206+
}
207+
}
208+
}
209+
200210
for (let m2 of Object.keys(list[v] || list[originalV])) {
201-
const v2 = list[v][m2];
211+
const v2 = (list[v] || list[originalV])[m2];
202212
if (DeviceModels.hasMatch(m2, model)) {
203213
match = v2;
204214
pattern = m2;
@@ -300,6 +310,17 @@ class DeviceModels {
300310
return `${pattern}`.replace('(?i)', '').replace('\\-', '-');
301311
}
302312

313+
/**
314+
* Make the pattern compatible with JavaScript key, remove something like O\+ and tranform it to O+
315+
*
316+
* @param {string} pattern
317+
*
318+
* @return {string}
319+
*/
320+
static getKey(pattern) {
321+
return `${pattern}`.replace('\\', '');
322+
}
323+
303324
/**
304325
*
305326
* @param {string} s

test/data/mobile/browser-other.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
headers: 'User-Agent: Prince/7.1 (http://www.princexml.com)'
1111
readable: 'Prince 7.1'
1212
result: { browser: { name: Prince, version: '7.1', type: browser } }
13+
-
14+
headers: 'User-Agent: Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; O+ 8.36 Android Build/Oplus8.36_Oplus) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
15+
readable: 'Android Browser on an O+ 8.36 Android running Android 4.1.1'
16+
result: { browser: { name: Android Browser }, device: { model: "O+ 8.36 Android", type: "mobile", subtype: "smart"}, engine: { name: Webkit, version: '534.30'}, os: { name: Android, version: 4.1.1 } }

0 commit comments

Comments
 (0)