Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element.cssSelector() generates invalid queries if the class or ID is invalid; needs escaping #1742

Closed
cyberbeat opened this issue Apr 7, 2022 · 3 comments
Assignees
Labels
bug Confirmed bug that we should fix fixed
Milestone

Comments

@cyberbeat
Copy link

cyberbeat commented Apr 7, 2022

org.jsoup.select.Selector$SelectorParseException: Could not parse query 'section.event-list.grid.md:grid-cols-2.lg:grid-cols-3.gap-8.md:gap-12.lg:gap-16.lg:block': unexpected token at ':grid-cols-2.lg:grid-cols-3.gap-8.md:gap-12.lg:gap-16.lg:block'
        at org.jsoup.select.QueryParser.findElements(QueryParser.java:218)
        at org.jsoup.select.QueryParser.parse(QueryParser.java:74)
        at org.jsoup.select.QueryParser.parse(QueryParser.java:45)
        at org.jsoup.select.QueryParser.combinator(QueryParser.java:90)
        at org.jsoup.select.QueryParser.parse(QueryParser.java:60)
        at org.jsoup.select.QueryParser.parse(QueryParser.java:45)
        at org.jsoup.select.Selector.select(Selector.java:95)
        at org.jsoup.nodes.Element.select(Element.java:421)
        at org.jsoup.nodes.Element.cssSelector(Element.java:838)

Seems that jsoup cannot parse it's own generated query.

Using jsoup 1.14.3

@jhy
Copy link
Owner

jhy commented May 15, 2022

Can you provide a simple test case with the input query / HTML so this can be reproed / understood?

@jhy jhy added the needs-more-info More information is needed from the reporter to progress the issue label May 15, 2022
@cyberbeat
Copy link
Author

I don't have the html-example anymore. But it seems, that the html contains some classes like "grid.md:grid-cols-2", so it must look like
<section class="grid.md:grid-cols-2 lg:grid-cols-3">.. maybe it is invalid html/css, but jsoup should not crash, with its own document-model.

There is no input query, because jsoup generated its own query (Element.cssSelector method)

@jhy jhy added bug Confirmed bug that we should fix and removed needs-more-info More information is needed from the reporter to progress the issue labels Jan 6, 2023
@jhy jhy changed the title Element.cssSelector() fails with org.jsoup.select.Selector$SelectorParseException: Could not parse query Element.cssSelector() generates invalid queries if the class or ID is invalid; needs escaping Jan 6, 2023
@jhy
Copy link
Owner

jhy commented Jan 6, 2023

This can be fixed by implementing escapes in the query parser for IDs and classes (etc). E.g. an updated / revised #1442. And then apply the escapes in the cssSelector method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug that we should fix fixed
Projects
None yet
Development

No branches or pull requests

2 participants