Only check for direct properties from the headers object

This commit is contained in:
Faisal Salman 2025-08-26 22:29:08 +07:00
parent 3e65196b57
commit fb1ed5cf6b
2 changed files with 9 additions and 1 deletions

View File

@ -1400,7 +1400,9 @@
// Normalize headers field name into lowercase
var normalized = {};
for (var header in headers) {
normalized[String(header).toLowerCase()] = headers[header];
if (headers.hasOwnProperty(header)) {
normalized[String(header).toLowerCase()] = headers[header];
}
}
headers = normalized;
}

View File

@ -389,4 +389,10 @@ describe('Read user-agent data from req.headers', function () {
const { browser } = UAParser(hEaDeRs);
assert.strictEqual(browser.toString(), "Midori 0.2.2");
});
it('Empty headers should not raise any error', function () {
const emptyHeaders = {};
const { browser } = UAParser(emptyHeaders);
assert.strictEqual(browser.toString(), "undefined");
});
});