Skip to content

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

Closed as not planned

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

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Nov 1, 2025
  2. T90REAL commented on Nov 1, 2025

    @T90REAL
    Author

    Not only empty string, but also some incomplete tag such as '<ª' would trigger this assertion.

  3. added
    stdlibStandard Library Python modules in the Lib/ directory
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Nov 1, 2025
  4. efimov-mikhail commented on Nov 1, 2025

    @efimov-mikhail
    Member
  5. serhiy-storchaka commented on Nov 1, 2025

    @serhiy-storchaka
    Member

    This works as expected. check_for_whole_start_tag() should only be called if the next characters are < followed by an ASCII letter. Assertions just check an internal consistency of the code.

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.13only security fixes3.14bugs and security fixes3.15bugs 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