Repository: capricorn86/happy-dom (ts)

Issue:
XMLParser Error
e.g. 
```javascript
const { Window } = require("../packages/happy-dom");

const window = new Window(), document = window.document;

document.write(`<html>
<!--[if lt IE 9]>
    <script>window.location = 'browser.htm';</script>
<![endif]-->
</html>`);

console.log(window.location);

```
this will result in incorrect loading scripts `window.location = 'browser.htm';`

Pull request description:
#519@patch: Fixes XMLParser Bug.
Fix #519

e.g.

```javascript
const window = new Window(), document = window.document;

const html = `<html>
<!--[if lt IE 9]>
    <script>window.location = 'browser.htm';</script>
<![endif]-->
</html>`;
document.write(html);

const source = new window.XMLSerializer().serializeToString(document);
console.assert(source === html);
console.log(window.location);

// Location {
// 	href: 'about:blank',
// 		origin: 'null',
// 		protocol: 'about:',
// 		username: '',
// 		password: '',
// 		host: '',
// 		hostname: '',
// 		port: '',
// 		pathname: 'blank',
// 		search: '',
// 		searchParams: URLSearchParams {},
// 	hash: ''
// }
```

Patch:
diff --git a/packages/happy-dom/src/xml-parser/XMLParser.ts b/packages/happy-dom/src/xml-parser/XMLParser.ts
index fc704af0..b2334a41 100755
--- a/packages/happy-dom/src/xml-parser/XMLParser.ts
+++ b/packages/happy-dom/src/xml-parser/XMLParser.ts
@@ -13,6 +13,9 @@ import HTMLLinkElement from '../nodes/html-link-element/HTMLLinkElement';
 import IDocumentFragment from '../nodes/document-fragment/IDocumentFragment';
 import PlainTextElements from '../config/PlainTextElements';
 
+const CONDITION_COMMENT_REGEXP =
+	/<!(--)?\[if (!|le|lt|lte|gt|gte|\(.*\)|&|\|| |IE|WindowsEdition|Contoso|true|false|\d+\.?(\d+)?|)*\]>/gi;
+const CONDITION_COMMENT_END_REGEXP = /<!\[endif\](--)?>/gi;
 const MARKUP_REGEXP = /<(\/?)([a-z][-.0-9_a-z]*)\s*([^<>]*?)(\/?)>/gi;
 const COMMENT_REGEXP = /<!--(.*?)-->|<([!?])([^>]*)>/gi;
 const DOCUMENT_TYPE_ATTRIBUTE_REGEXP = /"([^"]+)"/gm;
@@ -56,7 +59,23 @@ export default class XMLParser {
 					if (parentTagName && PlainTextElements.includes(parentTagName)) {
 						parent.appendChild(document.createTextNode(text));
 					} else {
-						this.appendTextAndCommentNodes(document, parent, text);
+						let condCommMatch;
+						let condCommEndMatch;
+						const condCommRegexp = new RegExp(CONDITION_COMMENT_REGEXP, 'gi');
+						const condCommEndRegexp = new RegExp(CONDITION_COMMENT_END_REGEXP, 'gi');
+						// @Refer: https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/?redirectedfrom=MSDN
+						if (
+							isStartTag &&
+							(condCommMatch = condCommRegexp.exec(text)) &&
+							condCommMatch[0] &&
+							(condCommEndMatch = condCommEndRegexp.exec(data.substring(markupRegexp.lastIndex))) &&
+							condCommEndMatch[0]
+						) {
+							markupRegexp.lastIndex += condCommEndRegexp.lastIndex;
+							continue;
+						} else {
+							this.appendTextAndCommentNodes(document, parent, text);
+						}
 					}
 				}
 


Test patch:
diff --git a/packages/happy-dom/test/xml-parser/XMLParser.test.ts b/packages/happy-dom/test/xml-parser/XMLParser.test.ts
index f30c525f..85dde35a 100644
--- a/packages/happy-dom/test/xml-parser/XMLParser.test.ts
+++ b/packages/happy-dom/test/xml-parser/XMLParser.test.ts
@@ -410,5 +410,58 @@ describe('XMLParser', () => {
 			const root4 = XMLParser.parse(window.document, <string>(<unknown>false));
 			expect(new XMLSerializer().serializeToString(root4)).toBe('false');
 		});
+
+		it('Parses conditional comments', () => {
+			const testHTML = [
+				'<!--[if IE 8]>\n' + '<p>Welcome to Internet Explorer 8.</p>\n' + '<![endif]-->',
+
+				'<!--[if gte IE 7]>\n' +
+					'<script>\n' +
+					'  alert("Congratulations! You are running Internet Explorer 7 or a later version of Internet Explorer.");\n' +
+					'</script>\n' +
+					'<p>Thank you for closing the message box.</p>\n' +
+					'<![endif]-->',
+
+				'<!--[if IE 5]>\n' +
+					'<p>Welcome to any incremental version of Internet Explorer 5!</p>\n' +
+					'<![endif]-->',
+
+				'<!--[if IE 5.0000]>\n' + '<p>Welcome to Internet Explorer 5.0!</p>\n' + '<![endif]-->',
+
+				'<!--[if WindowsEdition 1]>\n' +
+					'<p>You are using Windows Ultimate Edition.</p>\n' +
+					'<![endif]-->',
+
+				'<!--[if lt Contoso 2]>\n' +
+					'<p>Your version of the Contoso control is out of date; Please update to the latest.</p>\n' +
+					'<![endif]-->',
+
+				'<!DOCTYPE html><html lang="en">\n' +
+					'<head>\n' +
+					'    <meta charset="UTF-8">\n' +
+					'    <title>Title</title>\n' +
+					'</head>\n' +
+					'<body>\n' +
+					'<!--[if lt IE 9]>\n' +
+					"<script>window.location = 'browser.htm';</script>\n" +
+					'<![endif]-->\n' +
+					'\n' +
+					'\n' +
+					'<script>\n' +
+					"    const node = document.createElement('a');\n" +
+					"    node.href = 'http://www.google.com';\n" +
+					"    node.target = '_blank';\n" +
+					"    node.innerHTML = 'google';\n" +
+					'    window.document.body.appendChild(node);\n' +
+					'</script>\n' +
+					'</body>\n' +
+					'</html>\n'
+			];
+
+			for (const html of testHTML) {
+				const root = XMLParser.parse(window.document, html);
+				expect(new XMLSerializer().serializeToString(root)).toBe(html);
+			}
+		});
 	});
 });