Skip to content

Commit

Permalink
Fix undefined brandName when reading a field list that has no version
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalman committed Dec 20, 2023
1 parent 3622b61 commit 09904a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/ua-parser.js
Expand Up @@ -1056,7 +1056,7 @@
var brands = uaCH[FULLVERLIST] || uaCH[BRANDS];
if (brands) {
for (var i in brands) {
var brandName = brands[i].brand,
var brandName = brands[i].brand || brands[i],
brandVersion = brands[i].version;
if (!/not.a.brand/i.test(brandName) && (i < 1 || /chromi/i.test(this.get(NAME)))) {
this.set(NAME, strip(GOOGLE+' ', brandName))
Expand Down
22 changes: 22 additions & 0 deletions test/mocha-test.js
Expand Up @@ -490,4 +490,26 @@ describe('Map UA-CH headers', function () {
assert.strictEqual(ua.device.type, undefined);
});
});

it('Avoid error on headers variation', function () {

const headers2 = {
'sec-ch-ua' : '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
'sec-ch-ua-full-version-list' : '"Google Chrome", "Chromium", "Not?A_Brand";v="24.0.0.0"',
'sec-ch-ua-full-version' : '""',
'sec-ch-ua-mobile' : '?0',
'sec-ch-ua-arch' : '""',
'sec-ch-ua-bitness' : '""',
'sec-ch-ua-model' : '""',
'sec-ch-ua-platform' : '"Windows"',
'sec-ch-ua-platform-version' : '""',
'sec-ch-ua-wow64' : '?0',
};

uap = UAParser(headers2).withClientHints();

assert.strictEqual(uap.browser.name, "Chrome");
assert.strictEqual(uap.browser.version, undefined);
assert.strictEqual(uap.browser.major, undefined);
});
});

0 comments on commit 09904a0

Please sign in to comment.