Skip to content

xml.sax.xmlreader.AttributesImpl allows empty string as attribute names #57092

Open

Description

@MichaelSulyaev
BPO 12883
Nosy @iritkatriel
Files
  • w.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2011-09-02.10:04:02.189>
    labels = ['expert-XML', 'type-bug', '3.11']
    title = 'xml.sax.xmlreader.AttributesImpl allows empty string as attribute names'
    updated_at = <Date 2021-04-30.10:10:21.477>
    user = 'https://bugs.python.org/MichaelSulyaev'

    bugs.python.org fields:

    activity = <Date 2021-04-30.10:10:21.477>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['XML']
    creation = <Date 2011-09-02.10:04:02.189>
    creator = 'Michael.Sulyaev'
    dependencies = []
    files = ['28915']
    hgrepos = []
    issue_num = 12883
    keywords = ['patch']
    message_count = 4.0
    messages = ['143391', '180964', '181008', '392406']
    nosy_count = 4.0
    nosy_names = ['Ramchandra Apte', 'Michael.Sulyaev', 'Chenguang.Wang', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue12883'
    versions = ['Python 3.11']

    Linked PRs

    Activity

    1. MichaelSulyaev commented on Sep 2, 2011

      MichaelSulyaevmannequin
      MannequinAuthor

      I can get not-well-formed XML output (attribute name must not be empty string):

      <?xml version="1.0" encoding="iso-8859-1"?>
      <root ="v_for_empty_name" k1="v1"></root>

      AttributeImpl must ignore dict entries that may not be cast to valid XML attributes.

      Code:

      #!/usr/bin/python

      from xml.sax.xmlreader import AttributesImpl as Attrs
      from xml.sax.saxutils import XMLGenerator as Gen
      
      g = Gen()
      a = Attrs(dict([('k1','v1'),('','v_for_empty_name')]))
      g.startDocument()
      g.startElement('root',a)
      g.endElement('root')
      g.endDocument()
      print
    2. added
      type-bug
      on Sep 2, 2011
    3. RamchandraApte commented on Jan 30, 2013

      RamchandraAptemannequin
      Mannequin

      bump...

    4. ChenguangWang commented on Jan 31, 2013

      ChenguangWangmannequin
      Mannequin

      I found this problem is still not fixed in the lastest hg version. Seriously?

      This patch is for the latest v3.4.0a0.

    5. iritkatriel commented on Apr 30, 2021

      @iritkatriel
      Member

      I don't think the proposed patch is an acceptable solution. It silently skips invalid attributes.

      It would be ok to either raise an exception or to leave it as it is (junk-in-junk-out). I'm not sure which is better.

    6. added
      3.11
      on Apr 30, 2021
    7. transferred this issue fromon Apr 10, 2022
    8. added
      type-feature
      stdlib
      3.13
      and removed
      type-bug
      3.11
      on Nov 22, 2023
    9. iritkatriel commented on Nov 22, 2023

      @iritkatriel
      Member

      The documentation doesn't say anything about input validation, so this is a feature request rather than a bug.

    10. serhiy-storchaka commented on Sep 1, 2026

      @serhiy-storchaka
      Member

      PR #156800 adds the validate option instead of always checking the input.

      XMLGenerator is a content handler, so its usual input is the output of a parser, which is always valid. Validating names and characters almost doubles the time of generating a document, and everybody would pay for this. With validate=True the example from the first message is rejected with ValueError, as are illegal characters, invalid namespace prefixes and processing instructions which cannot be represented in a well-formed document.

      This matches the validate option proposed for xml.etree.ElementTree in #149469.

      While writing it I found that namespace URIs are not escaped at all, which is a separate bug: gh-156797, PR #156799.

    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.13stdlibtopic-XMLtype-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions