diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 44e13ccd60c..a65637d79ad 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -14,6 +14,7 @@ _Released 12/16/2025 (PENDING)_ - Fixed an issue where the browser would freeze when Cypress intercepts a synchronous XHR request and a `routeHandler` is used. Fixes [#32874](https://github.com/cypress-io/cypress/issues/32874). Addressed in [#32925](https://github.com/cypress-io/cypress/pull/32925). - Fixed an issue where `Next.js` Component Testing would not load correctly without a TypeScript-based Next config in versions 16.0.3 and up. Fixes [#32968](https://github.com/cypress-io/cypress/issues/32968). - Fixed an issue where the error message for `not.have.length` was not correctly displaying the expected length in the Command Log. Addressed in [#18927](https://github.com/cypress-io/cypress/issues/18927). +- Fixed an issue where `removeAttribute()` would not work for attributes other than `target` on anchor or form elements after clicking links with `target="_top"` or `target="_parent"`. Fixes [#26206](https://github.com/cypress-io/cypress/issues/26206). Addressed in [#33051](https://github.com/cypress-io/cypress/pull/33051). ## 15.7.1 diff --git a/packages/driver/cypress/e2e/issues/26206.cy.js b/packages/driver/cypress/e2e/issues/26206.cy.js new file mode 100644 index 00000000000..fee95d6eea2 --- /dev/null +++ b/packages/driver/cypress/e2e/issues/26206.cy.js @@ -0,0 +1,14 @@ +// https://github.com/cypress-io/cypress/issues/26206 +describe('issue 26206', () => { + beforeEach(() => { + cy.visit('fixtures/issue-26206.html') + }) + + it('removeAttribute works for non-target attributes after handleInvalidTarget', () => { + // After clicking an anchor with target="_top", the handleInvalidTarget function + // patches the element's removeAttribute. The bug was that removeAttribute + // would not work for attributes other than 'target'. + cy.get('#link').click() + cy.get('#result').should('have.text', 'removed') + }) +}) diff --git a/packages/driver/cypress/fixtures/issue-26206.html b/packages/driver/cypress/fixtures/issue-26206.html new file mode 100644 index 00000000000..d6de5a80ed7 --- /dev/null +++ b/packages/driver/cypress/fixtures/issue-26206.html @@ -0,0 +1,18 @@ + + + + + + + +
+ link +
+
+ + diff --git a/packages/driver/src/cy/top_attr_guards.ts b/packages/driver/src/cy/top_attr_guards.ts index cb98268d6c3..b321876e603 100644 --- a/packages/driver/src/cy/top_attr_guards.ts +++ b/packages/driver/src/cy/top_attr_guards.ts @@ -72,10 +72,10 @@ export function handleInvalidTarget (el: HTMLFormElement | HTMLAnchorElement) { if (k === 'target') { targetSet = false targetValue = '' - - // We're not using `$elements.callNativeMethod` here because it disallows `removeAttribute`. - return removeAttribute.call(this, k) } + + // We're not using `$elements.callNativeMethod` here because it disallows `removeAttribute`. + return removeAttribute.call(this, k) } if (!targetDescriptor) {