From 9478f22acf2fdb7b97c301fa4d45d33a01b29957 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 28 May 2025 11:23:38 +0000 Subject: [PATCH] refactor: avoid direct use of Object.prototype builtins 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 replaces direct invocations of built-in methods on objects with safe, unbound references to prevent unexpected behavior when those methods are overridden. - `Object.prototype builtins should not be used directly`: DeepSource flagged the direct use of methods like `obj.hasOwnProperty(key)` because an object’s own properties can shadow built-ins. We refactored these calls to use `Object.prototype.hasOwnProperty.call(obj, key)` (or `Object.hasOwn(obj, key)` where supported) to ensure reliability and security. --- 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]); } }