Skip to content

html.parser: check_for_whole_start_tag crashes with AssertionError on empty string #140877

Description

@T90REAL

Bug report

Bug description:

The html.parser.HTMLParser method check_for_whole_start_tag crashes with an AssertionError when its rawdata is an empty string.

from html.parser import HTMLParser

parser = HTMLParser()

parser.feed('')

result = parser.check_for_whole_start_tag(0)
Traceback (most recent call last):
  File "/data/src/test.py", line 11, in <module>
    result = parser.check_for_whole_start_tag(0)
  File "/home/hdd/miniconda3/lib/python3.13/html/parser.py", line 394, in check_for_whole_start_tag
    raise AssertionError("we should not get here!")
AssertionError: we should not get here!

I think the internal code should gracefully handle this None match by returning -1 instead if an AssertionError?

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions