Thanks to visit codestin.com
Credit goes to github.com

Skip to content

The Python implementation of xml.etree.ElementTree.XMLParser does not report a DOCTYPE without an external identifier #157406

Description

@serhiy-storchaka

Bug report

The pure Python implementation of xml.etree.ElementTree.XMLParser does not call the doctype() method of the target for a document type declaration without an external identifier, like <!DOCTYPE html> or <!DOCTYPE r [<!ENTITY e "v">]>. The C implementation calls it.

>>> import sys; sys.modules['_elementtree'] = None
>>> import xml.etree.ElementTree as ET
>>> class Target:
...     def doctype(self, *args): print(args)
...     def close(self): pass
...
>>> ET.XMLParser(target=Target()).feed('<!DOCTYPE html><html/>')
>>> ET.XMLParser(target=Target()).feed('<!DOCTYPE r SYSTEM "r.dtd"><r/>')
('r', None, 'r.dtd')

The C implementation prints ('html', None, None) for the first document.

The Python implementation does not use the StartDoctypeDeclHandler of Expat. It reconstructs the declaration from the tokens passed to the default handler, and only reports it after name SYSTEM "..." or name PUBLIC "..." "...". If > or [ follows the name, nothing is reported.

Linked PRs

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 fixes3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions