Skip to content

Commit

Permalink
Failing to parse iPhone iOS 10.0.1 UA ? #64
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksejs Gordejevs committed Feb 7, 2018
1 parent dcaca68 commit 995f49d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
18 changes: 17 additions & 1 deletion lib/express-useragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
PhantomJS: /phantomjs\/([\d\w\.\-]+)/i,
AlamoFire: /alamofire\/([\d\w\.\-]+)/i,
UC: /ucbrowser\/([\d\w\.]+)/i,
Facebook: /FBAV\/([\d\w\.]+)/i
Facebook: /FBAV\/([\d\w\.]+)/i,
WebKit: /applewebkit\/([\d\w\.]+)/i
};
this._Browsers = {
Edge: /edge|edga|edgios/i,
Expand Down Expand Up @@ -411,6 +412,12 @@
if (regex.test(string)) {
return RegExp.$1;
}
} else {
this.testWebkit();
if (this.Agent.isWebkit && this._Versions.WebKit.test(string)) {
return RegExp.$1;
}
return 'unknown';
}
}
};
Expand Down Expand Up @@ -753,6 +760,14 @@
}
};

this.testWebkit = function testWebkit() {
var ua = this;
if (ua.Agent.browser === 'unknown' && /applewebkit/i.test(ua.Agent.source)) {
ua.Agent.browser = 'Apple WebKit';
ua.Agent.isWebkit = true;
}
};

this.parse = function parse(source) {
var ua = new UserAgent();
ua.Agent.source = source.replace(/^\s*/, '').replace(/\s*$/, '');
Expand All @@ -769,6 +784,7 @@
ua.testSilk();
ua.testKindleFire();
ua.testCaptiveNetwork();
ua.testWebkit();
return ua.Agent;
};

Expand Down
2 changes: 1 addition & 1 deletion lib/express-useragent.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,15 +986,15 @@ exports['Bada OS browser'] = function (test) {
test.ok(!a.isIE, 'IE');
test.ok(!a.isSafari, 'Safari');
test.ok(!a.isFirefox, 'Firefox');
test.ok(!a.isWebkit, 'Webkit');
test.ok(a.isWebkit, 'Webkit');
test.ok(!a.isChrome, 'Chrome');
test.ok(!a.isKonqueror, 'Konqueror');
test.ok(!a.isDesktop, 'Desktop');
test.ok(!a.isWindows, 'Windows');
test.ok(!a.isLinux, 'Linux');
test.ok(!a.isMac, 'Mac');
test.ok(!a.isWindowsPhone, 'Windows Phone');
test.equal(a.version, undefined);
test.equal(a.version, '533.1');

test.done();
};
Expand Down
32 changes: 32 additions & 0 deletions test/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,35 @@ exports['iOS AlamoFire'] = function (test) {

test.done();
};

exports['iPhone like OS X'] = function (test) {

var s = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_1 like Mac OS X) ' +
'AppleWebKit/602.1.50 (KHTML, like Gecko) Mobile/14A403';

var a = ua.parse(s);

test.ok(a.isMobile, 'Mobile');
test.ok(!a.isiPad, 'iPad');
test.ok(!a.isiPod, 'iPod');
test.ok(a.isiPhone, 'iPhone');
test.ok(!a.isAndroid, 'Android');
test.ok(!a.isBlackberry, 'Blackberry');
test.ok(!a.isOpera, 'Opera');
test.ok(!a.isIE, 'IE');
test.ok(!a.isSafari, 'Safari');
test.ok(!a.isFirefox, 'Firefox');
test.ok(a.isWebkit, 'Webkit');
test.ok(!a.isChrome, 'Chrome');
test.ok(!a.isKonqueror, 'Konqueror');
test.ok(!a.isDesktop, 'Desktop');
test.ok(!a.isWindows, 'Windows');
test.ok(!a.isLinux, 'Linux');
test.ok(a.isMac, 'Mac');
test.ok(!a.isWindowsPhone, 'Windows Phone');
test.equal(a.version, '602.1.50');

test.done();
};

//

0 comments on commit 995f49d

Please sign in to comment.