nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: capricorn86/happy-dom
Pull request #882 (2023-05-02 07:29:10)

#881@patch: Adds support for query selectors for attributes with empt…
…y value (e.g. '[attr1=""]').


Patch:
diff --git a/packages/happy-dom/src/query-selector/SelectorItem.ts b/packages/happy-dom/src/query-selector/SelectorItem.ts
index 137991de..baf8df13 100644
--- a/packages/happy-dom/src/query-selector/SelectorItem.ts
+++ b/packages/happy-dom/src/query-selector/SelectorItem.ts
@@ -271,7 +271,7 @@ export default class SelectorItem {
 			priorityWeight += 10;
 
 			if (attribute.value !== null) {
-				if (!elementAttribute.value) {
+				if (elementAttribute.value === null) {
 					return null;
 				}
 
diff --git a/packages/happy-dom/src/query-selector/SelectorParser.ts b/packages/happy-dom/src/query-selector/SelectorParser.ts
index e2201c8f..8bce953b 100644
--- a/packages/happy-dom/src/query-selector/SelectorParser.ts
+++ b/packages/happy-dom/src/query-selector/SelectorParser.ts
@@ -18,7 +18,7 @@ import DOMException from '../exception/DOMException';
  * Group 11: Combinator.
  */
 const SELECTOR_REGEXP =
-	/(\*)|([a-zA-Z0-9-]+)|#((?:[a-zA-Z0-9-_]|\\.)+)|\.((?:[a-zA-Z0-9-_]|\\.)+)|\[([a-zA-Z0-9-_]+)\]|\[([a-zA-Z0-9-_]+)([~|^$*]{0,1}) *= *["']{0,1}([^"']+)["']{0,1}\]|:([a-zA-Z-:]+)|\(([^)]+)\)|([ ,+>]*)/g;
+	/(\*)|([a-zA-Z0-9-]+)|#((?:[a-zA-Z0-9-_]|\\.)+)|\.((?:[a-zA-Z0-9-_]|\\.)+)|\[([a-zA-Z0-9-_]+)\]|\[([a-zA-Z0-9-_]+)([~|^$*]{0,1}) *= *["']{0,1}([^"']*)["']{0,1}\]|:([a-zA-Z-:]+)|\(([^)]+)\)|([ ,+>]*)/g;
 
 /**
  * Escaped Character RegExp.
@@ -96,7 +96,7 @@ export default class SelectorParser {
 						operator: null,
 						value: null
 					});
-				} else if (match[6] && match[8]) {
+				} else if (match[6] && match[8] !== undefined) {
 					currentSelectorItem.attributes = currentSelectorItem.attributes || [];
 					currentSelectorItem.attributes.push({
 						name: match[6].toLowerCase(),


Test patch:
diff --git a/packages/happy-dom/test/query-selector/QuerySelector.test.ts b/packages/happy-dom/test/query-selector/QuerySelector.test.ts
index b73a2b0f..04bd62da 100644
--- a/packages/happy-dom/test/query-selector/QuerySelector.test.ts
+++ b/packages/happy-dom/test/query-selector/QuerySelector.test.ts
@@ -300,6 +300,16 @@ describe('QuerySelector', () => {
 			expect(elements[1] === container.children[0].children[1].children[1]).toBe(true);
 		});
 
+		it('Returns all elements with matching attributes using "[attr1=""]".', () => {
+			const container = document.createElement('div');
+			container.innerHTML = QuerySelectorHTML.replace(/attr1="value1"/gm, 'attr1=""');
+			const elements = container.querySelectorAll('[attr1=""]');
+
+			expect(elements.length).toBe(2);
+			expect(elements[0] === container.children[0].children[1].children[0]).toBe(true);
+			expect(elements[1] === container.children[0].children[1].children[1]).toBe(true);
+		});
+
 		it('Returns all elements with matching attributes using "[attr1="word1.word2"]".', () => {
 			const container = document.createElement('div');
 			container.innerHTML = QuerySelectorHTML;
Repository: capricorn86/happy-dom
Pull request #917 (2023-05-13 09:57:05)

#916@patch: Handle comments with dash in text.


Patch:
diff --git a/packages/happy-dom/src/xml-parser/XMLParser.ts b/packages/happy-dom/src/xml-parser/XMLParser.ts
index 7b37084b..c3f66107 100755
--- a/packages/happy-dom/src/xml-parser/XMLParser.ts
+++ b/packages/happy-dom/src/xml-parser/XMLParser.ts
@@ -160,11 +160,17 @@ export default class XMLParser {
 						) {
 							// Comment.
 
-							currentNode.appendChild(
-								document.createComment(
-									Entities.decodeHTML((match[6] ? '?' : '') + (match[3] || match[4] || match[6]))
-								)
-							);
+							let comment: string;
+
+							if (match[3]) {
+								comment = match[3];
+							} else if (match[4]) {
+								comment = match[4].endsWith('--') ? match[4].slice(0, -2) : match[4];
+							} else {
+								comment = '?' + match[6];
+							}
+
+							currentNode.appendChild(document.createComment(Entities.decodeHTML(comment)));
 						} else if (match[5]) {
 							// Exclamation mark comment (usually <!DOCTYPE>).
 


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 9bb6eace..a6b62ec2 100644
--- a/packages/happy-dom/test/xml-parser/XMLParser.test.ts
+++ b/packages/happy-dom/test/xml-parser/XMLParser.test.ts
@@ -9,6 +9,7 @@ import NamespaceURI from '../../src/config/NamespaceURI';
 import DocumentType from '../../src/nodes/document-type/DocumentType';
 import XMLSerializer from '../../src/xml-serializer/XMLSerializer';
 import IHTMLTemplateElement from '../../src/nodes/html-template-element/IHTMLTemplateElement';
+import NodeTypeEnum from '../../src/nodes/node/NodeTypeEnum';
 
 const GET_EXPECTED_HTML = (html: string): string =>
 	html
@@ -506,6 +507,13 @@ describe('XMLParser', () => {
 			}
 		});
 
+		it('Parses comments with dash in them.', () => {
+			const root = XMLParser.parse(document, '<!-- comment with - in - it -->');
+			expect(root.childNodes.length).toBe(1);
+			expect(root.childNodes[0].nodeType).toBe(NodeTypeEnum.commentNode);
+			expect(root.childNodes[0].nodeValue).toBe(' comment with - in - it ');
+		});
+
 		it('Parses <template> elements, including its content.', () => {
 			const root = XMLParser.parse(document, '<div><template><tr><td></td></tr></template></div>');
 			expect(root.childNodes.length).toBe(1);
Repository: capricorn86/happy-dom
Pull request #920 (2023-05-13 12:18:23)

#819@patch: Fixes issue where non-string values did not get converted…
… to strings in CharacterData.data, CharacterData.nodeValue or CharacterData.textContent.


Patch:
diff --git a/packages/happy-dom/src/nodes/character-data/CharacterData.ts b/packages/happy-dom/src/nodes/character-data/CharacterData.ts
index 5d039ca9..3ec73899 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']++;


Test patch:
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 3d78644c..c18ef773 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 = <CharacterData>document.createComment('test');
 			node.data = 'new text';
 			expect(node.data).toBe('new text');
+			node.data = <string>(<unknown>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 = <string>(<unknown>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 = <string>(<unknown>0);
+			expect(node.textContent).toBe('0');
 		});
 	});
Repository: capricorn86/happy-dom
Pull request #926 (2023-05-18 19:09:11)

#923@patch: Fixes issue where attribute selectors with an operator an…
…d with a value without quatation marks no longer worked (e.g. "[attr^=value]").


Patch:
diff --git a/packages/happy-dom/src/query-selector/SelectorParser.ts b/packages/happy-dom/src/query-selector/SelectorParser.ts
index a7465c9e..fba1f3a3 100644
--- a/packages/happy-dom/src/query-selector/SelectorParser.ts
+++ b/packages/happy-dom/src/query-selector/SelectorParser.ts
@@ -142,7 +142,7 @@ export default class SelectorParser {
 						operator: match[11] || null,
 						value: match[12],
 						modifier: null,
-						regExp: this.getAttributeRegExp({ operator: match[7], value: match[8] })
+						regExp: this.getAttributeRegExp({ operator: match[11], value: match[12] })
 					});
 				} else if (match[13] && match[14]) {
 					currentSelectorItem.pseudos = currentSelectorItem.pseudos || [];


Test patch:
diff --git a/packages/happy-dom/test/query-selector/QuerySelector.test.ts b/packages/happy-dom/test/query-selector/QuerySelector.test.ts
index b4f07af5..9704bf80 100644
--- a/packages/happy-dom/test/query-selector/QuerySelector.test.ts
+++ b/packages/happy-dom/test/query-selector/QuerySelector.test.ts
@@ -473,6 +473,19 @@ describe('QuerySelector', () => {
 			expect(elements[4] === container.children[0].children[1].children[2]).toBe(true);
 		});
 
+		it('Returns all elements with an attribute value that begins with a specified value using "[class^=cl]".', () => {
+			const container = document.createElement('div');
+			container.innerHTML = QuerySelectorHTML;
+			const elements = container.querySelectorAll('[class^=cl]');
+
+			expect(elements.length).toBe(5);
+			expect(elements[0] === container.children[0]).toBe(true);
+			expect(elements[1] === container.children[0].children[1]).toBe(true);
+			expect(elements[2] === container.children[0].children[1].children[0]).toBe(true);
+			expect(elements[3] === container.children[0].children[1].children[1]).toBe(true);
+			expect(elements[4] === container.children[0].children[1].children[2]).toBe(true);
+		});
+
 		it('Returns all elements with an attribute value that ends with a specified value using "[class$="ss2"]".', () => {
 			const container = document.createElement('div');
 			container.innerHTML = QuerySelectorHTML;
Repository: capricorn86/happy-dom
Pull request #931 (2023-05-22 22:55:19)

#928@patch: Fixes problem with querySelectorAll() not always retirnin…
…g elements in document order.


Patch:
diff --git a/packages/happy-dom/src/query-selector/QuerySelector.ts b/packages/happy-dom/src/query-selector/QuerySelector.ts
index 59223b05..2b20cef7 100644
--- a/packages/happy-dom/src/query-selector/QuerySelector.ts
+++ b/packages/happy-dom/src/query-selector/QuerySelector.ts
@@ -221,7 +221,7 @@ export default class QuerySelector {
 
 		for (let i = 0, max = children.length; i < max; i++) {
 			const child = children[i];
-			const position = (documentPosition ? documentPosition + '>' : '') + i;
+			const position = (documentPosition ? documentPosition + '>' : '') + String.fromCharCode(i);
 
 			if (selectorItem.match(child)) {
 				if (!nextSelectorItem) {


Test patch:
diff --git a/packages/happy-dom/test/query-selector/QuerySelector.test.ts b/packages/happy-dom/test/query-selector/QuerySelector.test.ts
index 9704bf80..d9d2314d 100644
--- a/packages/happy-dom/test/query-selector/QuerySelector.test.ts
+++ b/packages/happy-dom/test/query-selector/QuerySelector.test.ts
@@ -128,6 +128,29 @@ describe('QuerySelector', () => {
 				'ccb',
 				'ccc'
 			]);
+
+			element.innerHTML = `
+            <div>0</div>
+            <button>1</button>
+            <div>2</div>
+            <div>3</div>
+            <div>4</div>
+            <div>5</div>
+            <div>6</div>
+            <div>7</div>
+            <button>8</button>
+            <button>9</button>
+            <button>10</button>
+            <button>11</button>
+            `;
+
+			expect(Array.from(element.querySelectorAll('button')).map((div) => div.textContent)).toEqual([
+				'1',
+				'8',
+				'9',
+				'10',
+				'11'
+			]);
 		});
 
 		it('Returns a NodeList with the method item().', () => {