Skip to content

Commit

Permalink
Fix #449 Lenovo Tablet
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalman committed Mar 17, 2021
1 parent d1ba5f5 commit 1a8cd67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ua-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@
/android.+lg(\-?[\d\w]+)\s+build/i
], [MODEL, [VENDOR, 'LG'], [TYPE, MOBILE]], [

/(lenovo)\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+))/i // Lenovo tablets
/(lenovo)\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+)|[\w-]+)/i // Lenovo tablets
], [VENDOR, MODEL, [TYPE, TABLET]], [
/android.+(ideatab[a-z0-9\-\s]+)/i // Lenovo
], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
Expand Down
18 changes: 18 additions & 0 deletions test/device-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@
"type": "tablet"
}
},
{
"desc": "Lenovo Tab 3 Pro",
"ua": "Mozilla/5.0 (Linux; Android 6.0.1; Lenovo YT3-X90F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.99 Safari/537.36",
"expect": {
"vendor": "Lenovo",
"model": "YT3-X90F",
"type": "tablet"
}
},
{
"desc": "Lenovo Tab 4",
"ua": "Mozilla/5.0 (Linux; Android 7.1.1; Lenovo TB-X304F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.99 Safari/537.36",
"expect": {
"vendor": "Lenovo",
"model": "TB-X304F",
"type": "tablet"
}
},
{
"desc": "LG Nexus 4",
"ua": "Mozilla/5.0 (Linux; Android 4.2.1; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19",
Expand Down

2 comments on commit 1a8cd67

@dani3l
Copy link
Contributor

@dani3l dani3l commented on 1a8cd67 Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit caused a lot of Lenovo phone to be detected as tablets:

Here are some examples, these are all smartphones but the script detect them as tablets:
Mozilla/5.0 (Linux; Android 6.0; Lenovo PB2-650M Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.105 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/311.0.0.44.117;]
Mozilla/5.0 (Linux; Android 7.0; Lenovo K33a48 Build/NRD90N; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.105 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/310.0.0.50.118;]
Mozilla/5.0 (Linux; Android 8.1.0; Lenovo L58041) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.105 Mobile Safari/537.36

This regex solves that:
/lenovo\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+)|yt[\d\w-]+|tb[\d\w-]+)/i
OR to be more exact:
/lenovo\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+)|yt[\d\w-]{6}|tb[\d\w-]{6})/i

@faisalman
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes I forgot the suffix.. Good catch.. Thanks! 👍

Please sign in to comment.