Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: capricorn86/happy-dom
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: df8425798252466767eefa81e92ce3c1f6befa9b
Choose a base ref
...
head repository: capricorn86/happy-dom
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f2d46b6881d1282228b6adf7fd8410980c59c978
Choose a head ref
  • 1 commit
  • 3 files changed
  • 2 contributors

Commits on Jan 31, 2025

  1. fix: [1706] Handle non string attribute removal gracefully (#1711)

    Co-authored-by: David Ortner <david@ortner.se>
    OlaviSau and capricorn86 authored Jan 31, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    f2d46b6 View commit details
1 change: 1 addition & 0 deletions packages/happy-dom/src/nodes/element/NamedNodeMap.ts
Original file line number Diff line number Diff line change
@@ -84,6 +84,7 @@ export default class NamedNodeMap {
* @returns Item.
*/
public getNamedItem(name: string): Attr | null {
name = String(name);
if (
this[PropertySymbol.ownerElement][PropertySymbol.namespaceURI] === NamespaceURI.html &&
this[PropertySymbol.ownerElement][PropertySymbol.ownerDocument][
6 changes: 6 additions & 0 deletions packages/happy-dom/test/nodes/element/Element.test.ts
Original file line number Diff line number Diff line change
@@ -1646,6 +1646,12 @@ describe('Element', () => {
element.removeAttribute('key1');
expect(element.attributes.length).toBe(0);
});

it('Should stringify a non string attribute and remove it', () => {
element.setAttribute('undefined', 'value1');
element.removeAttribute(undefined);
expect(element.attributes.length).toBe(0);
});
});

describe('removeAttributeNS()', () => {
5 changes: 5 additions & 0 deletions packages/happy-dom/test/nodes/element/NamedNodeMap.test.ts
Original file line number Diff line number Diff line change
@@ -129,6 +129,11 @@ describe('NamedNodeMap', () => {
expect(element.getAttribute('key')).toBe('value1');
expect(element.getAttributeNS('namespace', 'key')).toBe('value2');
});

it('Handles non string keys as strings', () => {
element.setAttribute('undefined', 'value1');
expect(element.getAttribute(undefined)).toBe('value1');
});
});

describe('setNamedItemNS()', () => {