Skip to content

Commit

Permalink
change to single line regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Paris Morgan committed Oct 4, 2021
1 parent 79535f5 commit 343d584
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/ua-parser.js
Expand Up @@ -632,10 +632,8 @@
], [MODEL, [VENDOR, GOOGLE], [TYPE, WEARABLE]], [
/droid.+; (wt63?0{2,3})\)/i
], [MODEL, [VENDOR, ZEBRA], [TYPE, WEARABLE]], [
/quest 2/i
], [[MODEL, 'Quest 2'], [VENDOR, FACEBOOK], [TYPE, WEARABLE]], [
/quest/i
], [[MODEL, 'Quest'], [VENDOR, FACEBOOK], [TYPE, WEARABLE]], [
/(quest( 2)?)/i // Oculus Quest
], [MODEL, [VENDOR, FACEBOOK], [TYPE, WEARABLE]], [

///////////////////
// EMBEDDED
Expand Down

1 comment on commit 343d584

@allankronmark
Copy link

Choose a reason for hiding this comment

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

@jackpoll

This (updated) pattern results in a false positive when user agent string contains the string "quest", e.g. python-requests/2.24.0, causing this to be incorrectly categorised a an Oculus Quest wearable.

(regex 1) A likely better pattern would be /\;\s?(Quest\s?\d{0,})/i as it takes into account future versions as well + doesn't result in the false positive as pattern matches ;quest and ; quest 2 and ; quest 23 and ;quest 12345 but NOT request or conquest or similar (i flag if you want it to be case insensitive)

(regex 2) Alternatively (and likely slightly better), if you don't want it to match ; Quest234, this pattern will do: /\;\s?(Quest\s\d{0,}|Quest)/i

Thoughts/reflections: Technically, the pattern should only be matching if the string contains both "quest" and "oculus", right? Something like /(quest.*?)\).*?oculus.*/i

UA strings I've tested against using both the first and second regex:
Mozilla/5.0 (X11; Linux x86_64; Quest 2) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36 - MATCH
Mozilla/5.0 (X11; Linux x86_64; Quest) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36 - MATCH
Mozilla/5.0 (X11; Linux x86_64; Quest 23) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36 - MATCH
Mozilla/5.0 (X11; Linux x86_64;Quest 2) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36 - MATCH
Mozilla/5.0 (X11; Linux x86_64;Quest) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36 - MATCH
Mozilla/5.0 (X11; Linux x86_64;Quest 23) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36 - MATCH
Mozilla/5.0 (X11; Linux x86_64;Quest23) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36 - MATCH with regex 1 / NO MATCH with regex 2
python-requests/2.24.0 - NO MATCH

On a side note, I haven't yet figured out how I can override the built-in pattern. If I use the extend feature to add a "device" pattern for the python-requests/2.24.0 UA string, the "Oculus Quest" pattern still takes effect (overrides my pattern).

Please sign in to comment.