skip malformed css selector (#3577)

This commit is contained in:
pedrohsdb
2025-10-01 11:24:43 -07:00
committed by GitHub
parent 4d2ee0c665
commit 0fce84a384

View File

@@ -763,7 +763,11 @@ function isHoverPointerElement(element, hoverStylesMap) {
} }
} }
if (shouldMatch || selector.includes(tagName)) { if (shouldMatch || selector.includes(tagName)) {
if (element.matches(selector) && styles.cursor === "pointer") { if (
isValidCSSSelector(selector) &&
element.matches(selector) &&
styles.cursor === "pointer"
) {
return true; return true;
} }
} }
@@ -2192,6 +2196,11 @@ async function getHoverStylesMap() {
// Get base selector without :hover // Get base selector without :hover
const baseSelector = hoverPart.replace(/:hover/g, "").trim(); const baseSelector = hoverPart.replace(/:hover/g, "").trim();
// Skip invalid CSS selectors
if (!isValidCSSSelector(baseSelector)) {
continue;
}
// Get or create styles object for this selector // Get or create styles object for this selector
let styles = hoverMap.get(baseSelector) || {}; let styles = hoverMap.get(baseSelector) || {};
@@ -2204,6 +2213,8 @@ async function getHoverStylesMap() {
// store it in a special format // store it in a special format
if (parts.length > 1) { if (parts.length > 1) {
const fullSelector = selector; const fullSelector = selector;
// Skip if the full selector is invalid
if (isValidCSSSelector(fullSelector)) {
styles["__nested__"] = styles["__nested__"] || []; styles["__nested__"] = styles["__nested__"] || [];
styles["__nested__"].push({ styles["__nested__"].push({
selector: fullSelector, selector: fullSelector,
@@ -2212,6 +2223,7 @@ async function getHoverStylesMap() {
), ),
}); });
} }
}
// only need the style which includes the cursor attribute. // only need the style which includes the cursor attribute.
if (!("cursor" in styles)) { if (!("cursor" in styles)) {