Fix #797: Iterate over brands as an array (#798)

This commit is contained in:
Aidan Nulman
2025-08-01 07:34:36 -04:00
committed by GitHub
parent ab299a23b7
commit ecbc0336b6
7 changed files with 39 additions and 7 deletions

View File

@@ -91,6 +91,34 @@ describe('Returns', function () {
});
done();
});
it('works even when Array.prototype has been mangled', function(done) {
const result = withMangledArrayProto(() => new UAParser('').getResult());
function withMangledArrayProto(fn, key = 'isEmpty', value = function() { return this.length === 0; }) {
const originalValue = Array.prototype[key];
const restore = Object.hasOwnProperty.call(Array.prototype, key)
? () => Array.prototype[key] = originalValue
: () => delete Array.prototype[key];
Array.prototype[key] = value;
const result = fn();
restore();
return result;
}
assert.deepEqual(result,
{
ua : '',
browser: { name: undefined, version: undefined, major: undefined, type: undefined },
cpu: { architecture: undefined },
device: { vendor: undefined, model: undefined, type: undefined },
engine: { name: undefined, version: undefined},
os: { name: undefined, version: undefined }
});
done();
});
});
describe('Extending Regex', function () {
@@ -353,4 +381,4 @@ describe('Read user-agent data from req.headers', function () {
const { browser } = UAParser(reqHeaders);
assert.strictEqual(browser.is('Midori'), true);
});
});
});