Skip to content

SelectorParseException is thrown on attempt to get cssSelector for element with class conating *: #2169

@valfirst

Description

@valfirst

Steps to reproduce:

package org.example;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class Main
{
    public static void main(String[] args)
    {
        String html = "<!DOCTYPE html><html><body>\n"
                      + "  <img class=\"vds-flex_1 vds-d_block lg:vds-d_flex vds-flex_column vds-items_flex-end [&amp;_>_*:first-child]:vds-pt_0\" href=\"https://any.host/gif.gif\"></img>\n"
                      + "</body></html>";
        Document document = Jsoup.parse(html);
        Element img = document.body().child(0);

        // Next line will throw org.jsoup.select.Selector$SelectorParseException
        String cssSelector = img.cssSelector();
    }
}

Exception:

org.jsoup.select.Selector$SelectorParseException: Could not parse query 'img.vds-flex_1.vds-d_block.lg\:vds-d_flex.vds-flex_column.vds-items_flex-end.\[\&_\>_*\:first-child\]\:vds-pt_0': unexpected token at '\:first-child\]\:vds-pt_0'
	at org.jsoup.select.QueryParser.consumeEvaluator(QueryParser.java:184)
	at org.jsoup.select.QueryParser.parse(QueryParser.java:75)
	at org.jsoup.select.QueryParser.parse(QueryParser.java:46)
	at org.jsoup.select.QueryParser.combinator(QueryParser.java:91)
	at org.jsoup.select.QueryParser.parse(QueryParser.java:61)
	at org.jsoup.select.QueryParser.parse(QueryParser.java:46)
	at org.jsoup.select.Selector.select(Selector.java:102)
	at org.jsoup.nodes.Element.select(Element.java:475)
	at org.jsoup.nodes.Element.cssSelectorComponent(Element.java:948)
	at org.jsoup.nodes.Element.cssSelector(Element.java:929)
	at org.example.Main.main(Main.java:18)

Metadata

Metadata

Assignees

Labels

fixedAn {bug|improvement} that has been {fixed|implemented}

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions