-
-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the regexp for generic browsers #310
Conversation
Pull Request Test Coverage Report for Build 551
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @ricardorauber, thanks for the PR. Seems pretty reasonable to have this fix, but I'd ask you to leave a comment in the codes about the solution.
src/parser-browsers.js
Outdated
@@ -590,9 +590,10 @@ const browsersList = [ | |||
{ | |||
test: [/.*/i], | |||
describe(ua) { | |||
const regexp = ua.search('\\(') === -1 ? /^(.*)\/(.*) / : /^(.*)\/(.*)[ \t]\((.*)/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you, please, leave a comment in the code with some details on why exactly we use this ua.search('\\(') === -1
here? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sure, I can definitely do that! The idea is to use the search on the string to check if it has the "(" char, in case there is a device information in the User Agent, otherwise use the old separator. Is it ok to put it like that or should I be more technical?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest creating a variable like const hasDeviceSpec = ua.search('\\(') !== -1;
and put a comment for it, that here we try to make sure that there are explicit details about the device in order to decide what regexp exactly we want to apply (as there is a specific decision based on that conclusion). It would make the code more understandable in the future :) Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @lancedikson, sorry for the delay, but I have made the changes, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks! Will merge it and release a new version soon!
Hi @lancedikson,
First of all, thanks for the awesome module!
Second, I was trying to set a custom user-agent for my iOS app
iOSApp/3.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X)
and right now the result isbrowser.name = iOSApp
andbrowser.version = 3.0 (iPad; CPU iPhone OS 12_1_4 like Mac OS
.I noticed that this is happening because of the regexp on
parser-browser.js:594-595
, so I came up with a slightly different regexp to get the correct data. With this, I was able to getbrowser.name = iOSApp
andbrowser.version = 3.0
.I hope this could help many other people as well :)