{"record":{"id":"1e26d2f97151eaa5","repo":"jhy/jsoup","slug":"css-identifier-expected-but-end-of-input-found","errorCode":null,"errorMessage":"CSS identifier expected, but end of input found","messagePattern":"CSS identifier expected, but end of input found","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/jsoup/parser/TokenQueue.java","lineNumber":327,"sourceCode":"     */\n    public String consumeElementSelector() {\n        return consumeEscapedCssIdentifier(ElementSelectorChars);\n    }\n    private static final char[] ElementSelectorChars = {'*', '|', '_', '-'};\n\n    /**\n     Consume a CSS identifier (ID or class) off the queue.\n     <p>Note: For backwards compatibility this method supports improperly formatted CSS identifiers, e.g. {@code 1} instead\n     of {@code \\31}.</p>\n\n     @return The unescaped identifier.\n     @throws IllegalArgumentException if an invalid escape sequence was found. Afterward, the state of the TokenQueue\n     is undefined.\n     @see <a href=\"https://www.w3.org/TR/css-syntax-3/#consume-name\">CSS Syntax Module Level 3, Consume an ident sequence</a>\n     @see <a href=\"https://www.w3.org/TR/css-syntax-3/#typedef-ident-token\">CSS Syntax Module Level 3, ident-token</a>\n     */\n    public String consumeCssIdentifier() {\n        if (isEmpty()) throw new IllegalArgumentException(\"CSS identifier expected, but end of input found\");\n\n        // Fast path for CSS identifiers that don't contain escape sequences.\n        String identifier = reader.consumeMatching(TokenQueue::isIdent);\n        char c = current();\n        if (c != Esc && c != Unicode_Null) {\n            // If we didn't end on an Esc or a Null, we consumed the whole identifier\n            return identifier;\n        }\n\n        // An escape sequence was found. Use a StringBuilder to store the decoded CSS identifier.\n        StringBuilder out = StringUtil.borrowBuilder();\n        if (!identifier.isEmpty()) {\n            // Copy the CSS identifier up to the first escape sequence.\n            out.append(identifier);\n        }\n\n        while (!isEmpty()) {\n            c = current();","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/jhy/jsoup/blob/9851ac5d9c576c6888910b5a51a2362bbc978959/src/main/java/org/jsoup/parser/TokenQueue.java#L309-L345","documentation":"Selector-syntax error raised by TokenQueue.consumeCssIdentifier: the queue was positioned at a CSS identifier (e.g. after a '#' or '.' in a selector) but input ended before any identifier character appeared. Typically caused by a truncated query such as \"div#\" or \".class>\" with nothing following, i.e. malformed user-supplied CSS rather than an internal bug.","triggerScenarios":"Thrown at src/main/java/org/jsoup/parser/TokenQueue.java:327 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Validate/complete the CSS selector string before passing it to jsoup; ensure every '#'/'.' prefix is followed by a name.","Catch Selector.SelectorParseException around Selector.parse and surface a 'selector is incomplete' message to the user.","Escape special characters in identifiers (e.g. numeric-leading IDs as \\31) so the identifier consumes at least one character."],"exampleFix":null,"handlingStrategy":"validation","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"}