Repository: capricorn86/happy-dom (ts)

Issue:
DOMParser ignoring semicolons in hexadecimal html entities
**Describe the bug**
Using DOMParser for a string with characters such as `&lt;` or `&gt;` does not remove the semicolon as does the browser version

**To Reproduce**
Steps to reproduce the behavior:
1. Create a test for this function:
```ts
function htmlDecode(input: string): string {
  const doc = new DOMParser().parseFromString(input, "text/html");
  return doc.documentElement.textContent;
}
```
Like so:
```ts
it("should decode HTML entities", () => {
  expect(htmlDecode('&#x3C;div&#x3E;Hello, world!&#x3C;/div&#x3E;')).toBe(
    '<div>Hello, world!</div>',
  );
});
```

![image](https://user-images.githubusercontent.com/61510135/233091744-694cedf9-6664-4d3f-b110-1474748f3a39.png)

**Expected behavior**
The DOMParser should remove the semicolons, as does the browser:
![image](https://user-images.githubusercontent.com/61510135/233649551-570788c6-8f63-436b-a742-876696d058f5.png)

**Screenshots**
Added inline

**Device:**
 - OS: Windows 10
 - Browser Chrome/Vitest
 - Version Vitest 0.30.1, happydom 9.8.0

**Additional context**
Add any other context about the problem here.


Pull request:
#870@patch: Convert HTML entities should include  semicolon.
fix #870

Patch:
diff --git a/packages/happy-dom/src/nodes/character-data/CharacterDataUtility.ts b/packages/happy-dom/src/nodes/character-data/CharacterDataUtility.ts
index 4976a0a1..f00799a7 100644
--- a/packages/happy-dom/src/nodes/character-data/CharacterDataUtility.ts
+++ b/packages/happy-dom/src/nodes/character-data/CharacterDataUtility.ts
@@ -2,23 +2,23 @@ import ICharacterData from './ICharacterData';
 
 const HTML_ENTITIES = [
 	{ regex: /&quot;/g, value: '"' },
-	{ regex: /&#34/g, value: '"' },
-	{ regex: /&#x22/g, value: '"' },
+	{ regex: /&#34;/g, value: '"' },
+	{ regex: /&#x22;/g, value: '"' },
 	{ regex: /&amp;/g, value: '&' },
-	{ regex: /&#38/g, value: '&' },
-	{ regex: /&#x26/g, value: '&' },
+	{ regex: /&#38;/g, value: '&' },
+	{ regex: /&#x26;/g, value: '&' },
 	{ regex: /&apos;/g, value: "'" },
-	{ regex: /&#39/g, value: "'" },
-	{ regex: /&#x27/g, value: "'" },
+	{ regex: /&#39;/g, value: "'" },
+	{ regex: /&#x27;/g, value: "'" },
 	{ regex: /&lt;/g, value: '<' },
-	{ regex: /&#60/g, value: '<' },
-	{ regex: /&#x3C/g, value: '<' },
+	{ regex: /&#60;/g, value: '<' },
+	{ regex: /&#x3C;/g, value: '<' },
 	{ regex: /&gt;/g, value: '>' },
-	{ regex: /&#62/g, value: '>' },
-	{ regex: /&#x3E/g, value: '>' },
+	{ regex: /&#62;/g, value: '>' },
+	{ regex: /&#x3E;/g, value: '>' },
 	{ regex: /&nbsp;/g, value: ' ' },
-	{ regex: /&#160/g, value: ' ' },
-	{ regex: /&#xA0/g, value: ' ' }
+	{ regex: /&#160;/g, value: ' ' },
+	{ regex: /&#xA0;/g, value: ' ' }
 ];
 
 /**


Test patch:
diff --git a/packages/happy-dom/test/nodes/element/Element.test.ts b/packages/happy-dom/test/nodes/element/Element.test.ts
index 7fe27f26..2175a197 100644
--- a/packages/happy-dom/test/nodes/element/Element.test.ts
+++ b/packages/happy-dom/test/nodes/element/Element.test.ts
@@ -142,6 +142,9 @@ describe('Element', () => {
 			const el2 = document.createElement('div');
 			el2.innerHTML = '<div id="testnode">&gt;&lt;&amp;&quot;&apos;&nbsp;&nbsp;</div>';
 			expect(el2.textContent).toBe('><&"\'  ');
+			const el3 = document.createElement('div');
+			el3.innerHTML = '&#x3C;div&#x3E;Hello, world!&#x3C;/div&#x3E;';
+			expect(el3.textContent).toBe('<div>Hello, world!</div>');
 		});
 	});