Hi,
I ran into what looks like a bug in query_selector when using CSS combinators.
I tested selectors using both child combinators (>) and descendant combinators ( ), and they all return no match in the example below.
If combinators are intentionally unsupported, could that please be documented clearly, and could query_selector return an error instead of silently producing an empty iterator?
Current behavior
These selectors all fail to match:
div > a
.article > a
section a
#articles a
section > div > a
#articles > .article > a
Expected behavior
A <a> should be matched for each selector in the HTML below.
Minimal reproduction
use tl;
const HTML: &str = r#"
<html>
<head>
<title>Articles</title>
</head>
<body>
<section id="articles">
<div class="article">
<a href="/post/1"><b>Post</b> <1></a>
</div>
</section>
</body>
</html>
"#;
fn main() {
let dom = tl::parse(HTML, tl::ParserOptions::default()).unwrap();
assert!(
dom.query_selector("div > a")
.expect("Failed to create selection iterator")
.next()
.is_some(),
"Cannot use child selector"
);
assert!(
dom.query_selector(".article > a")
.expect("Failed to create selection iterator")
.next()
.is_some(),
"Cannot use child selector with class"
);
assert!(
dom.query_selector("section a")
.expect("Failed to create selection iterator")
.next()
.is_some(),
"Cannot use descendant selector"
);
assert!(
dom.query_selector("#articles a")
.expect("Failed to create selection iterator")
.next()
.is_some(),
"Cannot use descendant selector with id"
);
assert!(
dom.query_selector("section > div > a")
.expect("Failed to create selection iterator")
.next()
.is_some(),
"Cannot use child selectors"
);
assert!(
dom.query_selector("#articles > .article > a")
.expect("Failed to create selection iterator")
.next()
.is_some(),
"Cannot use child selectors"
);
}
Hi,
I ran into what looks like a bug in
query_selectorwhen using CSS combinators.I tested selectors using both child combinators (
>) and descendant combinators (), and they all return no match in the example below.If combinators are intentionally unsupported, could that please be documented clearly, and could
query_selectorreturn an error instead of silently producing an empty iterator?Current behavior
These selectors all fail to match:
div > a.article > asection a#articles asection > div > a#articles > .article > aExpected behavior
A
<a>should be matched for each selector in the HTML below.Minimal reproduction