Skip to content

xml.dom.minidom parses comments as nodeValue of a node, if there is no space between the comment and the start tag #140526

@CommunistMountain

Description

@CommunistMountain

Bug report

Bug description:

"""test.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <foo>not_comment</foo>
    <bar><!--comment_1-->
        <bar/>
    </bar>
    <baz> <!--comment_2-->
        <baz/>
    </baz>
</root>"""
import xml.dom.minidom
tree = xml.dom.minidom.parse('test.xml')
root = tree.documentElement
for child_node in root.childNodes:
    if child_node.localName is not None:
        print(f"{child_node.localName}: '{child_node.firstChild.nodeValue}'")
        # foo: 'not_comment'
        # bar: 'comment_1'
        # baz: ' '

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirpendingThe issue will be closed if no feedback is providedtopic-XMLtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions