{"record":{"id":"c6e6e11129631342","repo":"RustPython/RustPython","slug":"expected-name-token-at-r","errorCode":null,"errorMessage":"expected name token at %r","messagePattern":"expected name token at %r","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Lib/_markupbase.py","lineNumber":390,"sourceCode":"                    return j\n\n    # Internal -- scan a name token and the new position and the token, or\n    # return -1 if we've reached the end of the buffer.\n    def _scan_name(self, i, declstartpos):\n        rawdata = self.rawdata\n        n = len(rawdata)\n        if i == n:\n            return None, -1\n        m = _declname_match(rawdata, i)\n        if m:\n            s = m.group()\n            name = s.strip()\n            if (i + len(s)) == n:\n                return None, -1  # end of buffer\n            return name.lower(), m.end()\n        else:\n            self.updatepos(declstartpos, i)\n            raise AssertionError(\n                \"expected name token at %r\" % rawdata[declstartpos:declstartpos+20]\n            )\n\n    # To be overridden -- handlers for unknown objects\n    def unknown_decl(self, data):\n        pass\n","sourceCodeStart":372,"sourceCodeEnd":397,"githubUrl":"https://github.com/RustPython/RustPython/blob/aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd/Lib/_markupbase.py#L372-L397","documentation":"_scan_name applies the name-token regex _declname_match (a letter followed by name characters and trailing whitespace); when it cannot match at a position where the grammar requires a name, AssertionError('expected name token at %r') is raised with a 20-character excerpt starting at the declaration plus the updated line/offset. It is called from parse_declaration, _parse_decl, parse_marked_section, and the internal-subset parsers.","triggerScenarios":"`HTMLParser().feed('<![ [ x ]]>')` - a marked section missing its status keyword; `<!DOCTYPE doc [<! x>` - an empty declaration name inside the subset; any declaration whose name position holds whitespace or punctuation.","commonSituations":"Templated placeholders used as names (`<!${decl}`); truncation mid-declaration; whitespace where a keyword must be.","solutions":["Catch AssertionError around feed()/close()","Fix the generator so declarations always carry a real name token where the grammar requires one","Call parser.close() after the last chunk so buffer-end states resolve as incomplete rather than misparsed"],"exampleFix":"# before\nparser.feed('<![ [ x ]]>')\n# AssertionError: expected name token at '<![ [ x ]]>...'\n\n# after\nimport re\ntext = re.sub(r'<!\\[\\s*\\[', '<![ignore[', text)\nparser.feed(text)","handlingStrategy":"try-catch","validationCode":"import re\n\ndef declarations_have_names(text: str) -> bool:\n    # '<!' or '<![' followed by a non-name character where a name is required\n    return not re.search(r'<!\\s*[^\\w>\\-\\[]|<!\\[\\s*\\[', text)","typeGuard":null,"tryCatchPattern":"try:\n    parser.feed(text)\n    parser.close()\nexcept AssertionError as e:\n    log.warning('declaration missing name token: %s', e)","preventionTips":["Ensure generators always emit a name token after '<!' and after '<!['","Call close() after the final chunk so truncated states resolve as incomplete","Catch AssertionError for untrusted markup"],"tags":["html-parser","markupbase","assertionerror","name-token","malformed-markup"],"backgroundTag":"html-parse-error","analyzedSha":"aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd","analyzedAt":"2026-08-17T00:37:52.100Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}