dangrossman/node-browscap — Issue #5: Wrong browser returned
Author: kersten
Created: 2011-11-08 09:05:42+00:00
State: open

Hi,

I've found out that your library does not return the correct values.

EG: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; CMDTDF; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E; BRI/1; InfoPath.2)

Returns IE 7 but i should be IE 8

I've fixed it by chaning the getBowser function, could you check if this is correct and fix it?

exports.getBrowser = function(userAgent) {
if (!browsers.length) {
browsers = parse(inifile)
}

var matches = new Array();

// Test user agent against each browser regex
for (var i = 0; i < browsers.length; i++) {
if (browsers[i].__regex__.test(userAgent)) {
matches.push(browsers[i]);
//return browsers[i]
}
}

return (matches.length == 1) ? matches[0] : matches[matches.length -2];
}