{"record":{"id":"37fabb540a899e78","repo":"jhy/jsoup","slug":"could-not-parse-query-s-unexpected-token-at","errorCode":null,"errorMessage":"Could not parse query '%s': unexpected token at '%s'","messagePattern":"Could not parse query '(.+?)': unexpected token at '(.+?)'","errorType":"exception","errorClass":"Selector.SelectorParseException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/jsoup/select/QueryParser.java","lineNumber":82,"sourceCode":"     Parse the query. We use this simplified expression of the grammar:\n     <pre>\n     SelectorGroup   ::= Selector (',' Selector)*\n     Selector        ::= [ Combinator ] SimpleSequence ( Combinator SimpleSequence )*\n     SimpleSequence  ::= [ TypeSelector ] ( ID | Class | Attribute | Pseudo )*\n     Pseudo           ::= ':' Name [ '(' SelectorGroup ')' ]\n     Combinator      ::= S+         // descendant (whitespace)\n     | '>'       // child\n     | '+'       // adjacent sibling\n     | '~'       // general sibling\n     </pre>\n\n     See <a href=\"https://www.w3.org/TR/selectors-4/#grammar\">selectors-4</a> for the real thing\n     */\n    Evaluator parse() {\n        Evaluator eval = parseSelectorGroup();\n        tq.consumeWhitespace();\n        if (!tq.isEmpty())\n            throw new Selector.SelectorParseException(\"Could not parse query '%s': unexpected token at '%s'\", query, tq.remainder());\n        return eval;\n    }\n\n    Evaluator parseSelectorGroup() {\n        // SelectorGroup. Into an Or if > 1 Selector\n        Evaluator left = parseSelector();\n        while (tq.matchChomp(',')) {\n            Evaluator right = parseSelector();\n            left = or(left, right);\n        }\n        return left;\n    }\n\n    Evaluator parseSelector() {\n        // Selector ::= [ Combinator ] SimpleSequence ( Combinator SimpleSequence )*\n        tq.consumeWhitespace();\n\n        Evaluator left;","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/jhy/jsoup/blob/9851ac5d9c576c6888910b5a51a2362bbc978959/src/main/java/org/jsoup/select/QueryParser.java#L64-L100","documentation":"Grammar error thrown by QueryParser.parse when the token stream stops at a character that does not fit the selector grammar (Selector / Combinator / SimpleSequence rules) — e.g. a stray operator, unmatched bracket, or unexpected character. The message includes the full query and the remainder where parsing failed, identifying the exact malformed input.","triggerScenarios":"Thrown at src/main/java/org/jsoup/select/QueryParser.java:82 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the remainder in the message to locate the offending character and fix the selector (e.g. stray '>', '~', or unbalanced ']').","Catch Selector.SelectorParseException when queries come from user input and return a targeted syntax error.","Use jsoup's documented selector syntax and validate against it before parsing."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9851ac5d9c576c6888910b5a51a2362bbc978959","analyzedAt":"2026-09-08T15:22:04.931Z","contentChangedAt":"2026-09-08T15:22:04.931Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}