cssSelector has a problem with '<div data-v-7a225e99="" class="flex-center gap-[12px]">'
The page contains such elements <div data-v-7a225e99="" class="flex-center gap-[12px]">.
It seems to be caused by a difference in the handling of "" by the two functions.
org.jsoup.select.QueryParser#consumeSubQuery
org.jsoup.parser.TokenQueue#chompBalanced
Can you provide a small test case that demonstrates what you're trying to do and what you expect?
An error will be raised when getting the cssSelector of the element.
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class Demo {
public static void main(String[] args) throws Exception {
String html = "<html>\n" +
"\n" +
"<head>\n" +
" <title>Jsoup Example</title>\n" +
"</head>\n" +
"\n" +
"<body>\n" +
" <div data-v-7a225e99=\"\" class=\"flex-center gap-[12px]\">\n" +
"</body>\n" +
"\n" +
"</html>";
Document doc = Jsoup.parse(html,"UTF-8");
doc.getElementsByTag("div").first().cssSelector();
}
}
Exception in thread "main" org.jsoup.select.Selector$SelectorParseException: Did not find balanced marker at '12px\]'
at org.jsoup.select.QueryParser.parse(QueryParser.java:48)
at org.jsoup.select.Selector.select(Selector.java:101)
at org.jsoup.nodes.Element.select(Element.java:474)
at org.jsoup.nodes.Element.cssSelectorComponent(Element.java:950)
at org.jsoup.nodes.Element.cssSelector(Element.java:928)
at Demo.main(Demo.java:21)
Thanks, actual code is worth a thousand pictures :)
Thanks, fixed.
This fixes the case that consumeSubQuery() didn't handle escape chars.
Per #1998, we also can do a better job of making the escapes, in the first place.