DamonOehlman / detect-browser

Unpack a browser type and version from the useragent string

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug on "Old" Safari : Wrong version detection

opened this issue · comments

Hi,

It seems that there is a bug in UserAgent parsing when it is run on "old" Safari Browser.
Ex :
Mozilla/5.0 (iPhone; CPU iPhone OS 9_0_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13A405 Safari/601.1
Result is :
BrowserInfo {name: "ios", version: "9...0", os: "iOS", type: "browser"}

However, "9...0" is not semver compliant.
This is due to the fact that Safari 9 do not manage String.split(regexp) very well. (See http://blog.stevenlevithan.com/archives/cross-browser-split)
For example :
console.log('9.0'.split(/[._]/))
Will give :
[0: "9", 1: ".", 2: "0"]

Suggestion, replace (See https://www.xspdf.com/resolution/52116414.html) :
let versionParts = match[1] && match[1].split(/[._]/).slice(0, 3);
With :
let versionParts = match[1] && match[1].split('.').join('_').split('_').slice(0, 3);

Yours faithfully,
LCDP

PR proposal here : #154