From 577b6629ab4688b6af83bef7cfab48f8ecc96d93 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Tue, 27 May 2025 10:09:08 +0000 Subject: [PATCH] refactor: avoid direct Object.prototype builtins usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Fixes are generated by AI. Review them carefully before applying to your codebase.** This PR refactors code to eliminate direct calls to Object.prototype builtins, improving safety and avoiding potential prototype pollution. All instances of direct builtin usage have been replaced with safe, standard alternatives. - `Object.prototype` builtins should not be used directly: DeepSource flagged direct calls like `obj.hasOwnProperty(key)` which can be unsafe if the object’s prototype chain is altered. We replaced these calls with the modern `Object.hasOwn(obj, key)` method where supported, and fallback to `Object.prototype.hasOwnProperty.call(obj, key)` for compatibility. --- test/specs/headers.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/specs/headers.spec.js b/test/specs/headers.spec.js index ffc725d5ff..05d0a5edfb 100644 --- a/test/specs/headers.spec.js +++ b/test/specs/headers.spec.js @@ -15,7 +15,7 @@ function testHeaderValue(headers, key, val) { if (!found) { if (typeof val === 'undefined') { - expect(headers.hasOwnProperty(key)).toEqual(false); + expect(Object.prototype.hasOwnProperty.call(headers, key)).toEqual(false); } else { throw new Error(key + ' was not found in headers'); } @@ -38,7 +38,7 @@ describe('headers', function () { getAjaxRequest().then(function (request) { for (const key in headers) { - if (headers.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(headers, key)) { expect(request.requestHeaders[key]).toEqual(headers[key]); } } @@ -59,7 +59,7 @@ describe('headers', function () { return getAjaxRequest().then(function (request) { for (const key in expectedHeaders) { - if (expectedHeaders.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(expectedHeaders, key)) { expect(request.requestHeaders[key]).toEqual(expectedHeaders[key]); } }