From 3734b7bf1473171360d325962ad00d69170b1c71 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Tue, 7 Oct 2025 15:31:21 +0000 Subject: [PATCH] refactor: replace direct hasOwnProperty calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR refactors the code to avoid calling built-in methods directly on objects. Each instance of `obj.hasOwnProperty(key)` has been replaced with `Object.prototype.hasOwnProperty.call(obj, key)` to ensure a safe, reliable property check regardless of an object’s prototype state. - Object.prototype builtins should not be used directly: The existing code invoked `hasOwnProperty` directly on objects like `headers` and `expectedHeaders`, which can lead to incorrect behavior if those objects have a null prototype or an overridden method. We updated all three occurrences to use `Object.prototype.hasOwnProperty.call(obj, key)`, safeguarding against prototype pollution and ensuring consistent behavior. > This Autofix was generated by AI. Please review the change before merging. --- 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]); } }