Skip to content

Commit bba8159

Browse files
committed
fix validation of has selector (and also for the pseudo element selector)
1 parent 9d55538 commit bba8159

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/main/java/org/htmlunit/css/CssStyleSheet.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,19 @@ private static boolean isValidSelector(final Selector selector, final DomNode do
11711171
final GeneralAdjacentSelector gas = (GeneralAdjacentSelector) selector;
11721172
return isValidSelector(gas.getSelector(), domNode)
11731173
&& isValidSelector(gas.getSimpleSelector(), domNode);
1174+
case PSEUDO_ELEMENT_SELECTOR:
1175+
// as of now (4.17) the htmlunit-cssparser accepts only supported selectors
1176+
// if ("first-line".equals(s)
1177+
// || "first-letter".equals(s)
1178+
// || "before".equals(s)
1179+
// || "after".equals(s))
1180+
// {
1181+
// return new PseudoElementSelector(s, locator, doubleColon);
1182+
// }
1183+
return true;
1184+
case RELATIVE_SELECTOR:
1185+
final RelativeSelector rs = (RelativeSelector) selector;
1186+
return isValidSelector(rs.getSelector(), domNode);
11741187
default:
11751188
if (LOG.isWarnEnabled()) {
11761189
LOG.warn("Unhandled CSS selector type '"

src/test/java/org/htmlunit/javascript/host/css/CSSSelector3Test.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,34 @@ public void hasAnd() throws Exception {
790790
loadPageVerifyTitle2(html);
791791
}
792792

793+
794+
/**
795+
* @throws Exception if the test fails
796+
*/
797+
@Test
798+
@Alerts({"0", "SyntaxError/DOMException"})
799+
public void hasSizzleJQuery182InvalidContains() throws Exception {
800+
final String html = DOCTYPE_HTML
801+
+ "<html>\n"
802+
+ "<head></head>\n"
803+
+ "<body>\n"
804+
805+
+ "<script>\n"
806+
+ LOG_TITLE_FUNCTION
807+
+ " try {\n"
808+
+ " items = document.querySelectorAll(\"#form select:has(option:first-child)\");"
809+
+ " log(items.length);\n"
810+
811+
+ " items = document.querySelectorAll(\"#form select:has(option:first-child:contains('o'))\");"
812+
+ " log(items.length);\n"
813+
+ " } catch (e) { logEx(e); }\n"
814+
+ "</script>\n"
815+
816+
+ "</body></html>";
817+
818+
loadPageVerifyTitle2(html);
819+
}
820+
793821
/**
794822
* @throws Exception if the test fails
795823
*/

0 commit comments

Comments
 (0)