From cda48cb48a0bdeaba69fe9779b545e70926e0cb8 Mon Sep 17 00:00:00 2001 From: hsteinbr Date: Fri, 1 May 2015 15:18:26 -0700 Subject: [PATCH] Parse user agent by default according to spec. http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html see 14.43 --- src/bowser.js | 12 +++++++++++- src/useragents.js | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/bowser.js b/src/bowser.js index 6547b0d..1da5331 100644 --- a/src/bowser.js +++ b/src/bowser.js @@ -16,6 +16,11 @@ return (match && match.length > 1 && match[1]) || ''; } + function getSecondMatch(regex) { + var match = ua.match(regex); + return (match && match.length > 1 && match[2]) || ''; + } + var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase() , likeAndroid = /like android/i.test(ua) , android = !likeAndroid && /android/i.test(ua) @@ -142,7 +147,12 @@ , version: versionIdentifier } } - else result = {} + else { + result = { + name: getFirstMatch(/^(.*)\/(.*) /), + version: getSecondMatch(/^(.*)\/(.*) /) + }; + } // set webkit or gecko flag for browsers based on these engines if (/(apple)?webkit/i.test(ua)) { diff --git a/src/useragents.js b/src/useragents.js index eaa0ab7..ba36d1c 100644 --- a/src/useragents.js +++ b/src/useragents.js @@ -931,4 +931,11 @@ module.exports.useragents = { , x: true } } + , Generic: { + 'Generic/2.15 libww': { + name: 'Generic' + , version: '2.15' + , x: true + } + } };