fix(traversing): Restrict reContextSelector to :scope

#4967 was overly broad
This commit is contained in:
Felix
2026-01-21 11:50:33 +00:00
parent 1ed7173ada
commit ae6d66d431

View File

@@ -24,7 +24,7 @@ import {
uniqueSort,
} from 'domutils';
import type { FilterFunction, AcceptedFilters } from '../types.js';
const reSiblingSelector = /^\s*[+~:]/;
const reContextSelector = /^\s*(?:[+~]|:scope\b)/;
/**
* Get the descendants of each element in the current set of matched elements,
@@ -83,7 +83,7 @@ export function _findBySelector<T extends AnyNode>(
): Cheerio<Element> {
const context = this.toArray();
const elems = reSiblingSelector.test(selector)
const elems = reContextSelector.test(selector)
? context
: this.children().toArray();