{"record":{"id":"c340d016a5d47c8a","repo":"python/cpython","slug":"unknown-status-keyword-r-in-marked-section","errorCode":null,"errorMessage":"unknown status keyword %r in marked section","messagePattern":"unknown status keyword %r in marked section","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Lib/_markupbase.py","lineNumber":154,"sourceCode":"                return j\n        return -1 # incomplete\n\n    # Internal -- parse a marked section\n    # Override this to handle MS-word extension syntax <![if word]>content<![endif]>\n    def parse_marked_section(self, i, report=1):\n        rawdata= self.rawdata\n        assert rawdata[i:i+3] == '<![', \"unexpected call to parse_marked_section()\"\n        sectName, j = self._scan_name( i+3, i )\n        if j < 0:\n            return j\n        if sectName in {\"temp\", \"cdata\", \"ignore\", \"include\", \"rcdata\"}:\n            # look for standard ]]> ending\n            match= _markedsectionclose.search(rawdata, i+3)\n        elif sectName in {\"if\", \"else\", \"endif\"}:\n            # look for MS Office ]> ending\n            match= _msmarkedsectionclose.search(rawdata, i+3)\n        else:\n            raise AssertionError(\n                'unknown status keyword %r in marked section' % rawdata[i+3:j]\n            )\n        if not match:\n            return -1\n        if report:\n            j = match.start(0)\n            self.unknown_decl(rawdata[i+3: j])\n        return match.end(0)\n\n    # Internal -- parse comment, return length or -1 if not terminated\n    def parse_comment(self, i, report=1):\n        rawdata = self.rawdata\n        if rawdata[i:i+4] != '<!--':\n            raise AssertionError('unexpected call to parse_comment()')\n        match = _commentclose.search(rawdata, i+4)\n        if not match:\n            return -1\n        if report:","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/_markupbase.py#L136-L172","documentation":"AssertionError raised by _markupbase.ParserBase.parse_marked_section when a <![keyword[ ... ]]> construct uses a status keyword the parser does not recognize. Only temp, cdata, ignore, include, rcdata (standard) and if, else, endif (MS Office downlevel-revealed conditionals) are accepted; anything else aborts.","triggerScenarios":"HTMLParser.feed() on markup like <![expect[ ... ]]> or <![switch[ ...]]> — sectName comes back unrecognized. Common with XML 'INCLUDE/IGNORE'-misspellings, CDATA variants, or proprietary marked sections in publishing/DTD files.","commonSituations":"Scraping legacy SGML documents and old help files; parsing XML with marked sections using a non-standard keyword; test corpora containing unusual <![...[ constructs.","solutions":["Preprocess: strip <![...[...]]> blocks with a regex (r'<!\\[.*?\\]\\]>|<!\\[.*?\\]>', DOTALL) before feeding.","Correct the keyword if you control the source: use CDATA/IGNORE/INCLUDE spellings.","Catch AssertionError and resume feeding after the section terminator (]]> or ]> for MS conditionals).","For documents that legitimately use marked sections, use an SGML-capable parser (lxml/opensp) rather than html.parser."],"exampleFix":"# before\nHTMLParser().feed('<![expect[ secret ]]>')  # AssertionError: unknown status keyword\n\n# after\nimport re\nfeed = re.sub(r'<!\\[.*?\\]\\]?>', '', raw, flags=re.S)\nHTMLParser().feed(feed)","handlingStrategy":"try-catch","validationCode":"import re\n_KNOWN_SECT = {'temp', 'cdata', 'ignore', 'include', 'rcdata', 'if', 'else', 'endif'}\n\ndef marked_sections_ok(raw: str) -> bool:\n    for m in re.finditer(r'<!\\[\\s*(\\w+)\\s*\\[', raw):\n        if m.group(1).lower() not in _KNOWN_SECT:\n            return False\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    parser.feed(data)\nexcept AssertionError as e:\n    if 'marked section' in str(e):\n        data = re.sub(r'<!\\[.*?\\]\\]?>', '', data, flags=re.S)\n        parser.reset(); parser.feed(data)\n    else:\n        raise","preventionTips":["Strip <![...[...]]> constructs from input destined for html.parser.","Override parse_marked_section/unknown_decl in a subclass for proprietary sections.","Keep marked-section handling in SGML-capable parsers."],"tags":["markup","html-parser","marked-section","parsing"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}