From ad5dffbf7bdd86786b66f539ba141e1a09804348 Mon Sep 17 00:00:00 2001 From: David Ortner Date: Sat, 13 May 2023 14:17:52 +0200 Subject: [PATCH] #819@patch: Fixes issue where non-string values did not get converted to strings in CharacterData.data, CharacterData.nodeValue or CharacterData.textContent. --- .../happy-dom/src/nodes/character-data/CharacterData.ts | 2 +- .../test/nodes/character-data/CharaterData.test.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/happy-dom/src/nodes/character-data/CharacterData.ts b/packages/happy-dom/src/nodes/character-data/CharacterData.ts index 5d039ca94..3ec738992 100644 --- a/packages/happy-dom/src/nodes/character-data/CharacterData.ts +++ b/packages/happy-dom/src/nodes/character-data/CharacterData.ts @@ -54,7 +54,7 @@ export default abstract class CharacterData extends Node implements ICharacterDa */ public set data(data: string) { const oldValue = this._data; - this._data = data; + this._data = String(data); if (this.isConnected) { this.ownerDocument['_cacheID']++; diff --git a/packages/happy-dom/test/nodes/character-data/CharaterData.test.ts b/packages/happy-dom/test/nodes/character-data/CharaterData.test.ts index 3d78644cf..c18ef773c 100644 --- a/packages/happy-dom/test/nodes/character-data/CharaterData.test.ts +++ b/packages/happy-dom/test/nodes/character-data/CharaterData.test.ts @@ -37,6 +37,8 @@ describe('CharaterData', () => { const node = document.createComment('test'); node.data = 'new text'; expect(node.data).toBe('new text'); + node.data = (0); + expect(node.data).toBe('0'); }); }); @@ -52,6 +54,8 @@ describe('CharaterData', () => { const node = document.createTextNode('test'); node.nodeValue = 'new text'; expect(node.nodeValue).toBe('new text'); + node.nodeValue = (0); + expect(node.nodeValue).toBe('0'); }); }); @@ -67,6 +71,8 @@ describe('CharaterData', () => { const node = document.createComment('test'); node.textContent = 'new text'; expect(node.textContent).toBe('new text'); + node.textContent = (0); + expect(node.textContent).toBe('0'); }); });