Skip to content

Commit d1fdbba

Browse files
fivefiltersdevnexen
authored andcommitted
Fix GH-24260: querySelectorAll() returns duplicate elements for selector lists
Close GH-24267
1 parent 59de8a8 commit d1fdbba

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ PHP NEWS
2323
- DOM:
2424
. Fixed bug GH-23352 (UAF reading an attribute value node retained across
2525
DOMDocument::adoptNode()). (David Carlier)
26+
. Fixed bug GH-24260 (querySelectorAll() returns duplicate elements for
27+
selector lists). (fivefilters)
2628

2729
- FPM:
2830
. Fixed bug GH-24229 (fcgi_close() passes shutdown() a literal 1, which is

‎ext/dom/parentnode/css_selectors.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void dom_parent_node_query_selector_all(xmlNodePtr thisp, dom_object *intern, zv
240240
selectors_str,
241241
dom_query_selector_find_array_callback,
242242
&ctx,
243-
LXB_SELECTORS_OPT_DEFAULT
243+
LXB_SELECTORS_OPT_MATCH_FIRST
244244
) != LXB_STATUS_OK) {
245245
zend_array_destroy(list);
246246
RETURN_THROWS();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
GH-24260 (querySelectorAll() returns duplicate elements for selector lists)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom = Dom\HTMLDocument::createFromString(
9+
'<!DOCTYPE html><div><p class="a b">one</p><p class="b">two</p></div>'
10+
);
11+
12+
foreach ([$dom, $dom->querySelector('div')] as $context) {
13+
foreach (['.a, .b', '.a, .b, .a.b', 'p, :is(.a, .b)'] as $selector) {
14+
$texts = [];
15+
foreach ($context->querySelectorAll($selector) as $node) {
16+
$texts[] = $node->textContent;
17+
}
18+
echo $selector, ': ', implode(' ', $texts), "\n";
19+
}
20+
}
21+
22+
?>
23+
--EXPECT--
24+
.a, .b: one two
25+
.a, .b, .a.b: one two
26+
p, :is(.a, .b): one two
27+
.a, .b: one two
28+
.a, .b, .a.b: one two
29+
p, :is(.a, .b): one two

0 commit comments

Comments
 (0)