classification
Title: Empty ('') xmlns attribute is not properly handled by xml.dom.minidom
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: AttributeError: 'NoneType' object has no attribute 'replace'
View: 5762
Assigned To: Nosy List: BreamoreBoy, atamyrat, ezio.melotti, ned.deily
Priority: normal Keywords:

Created on 2011-05-12 21:11 by atamyrat, last changed 2014-06-24 06:38 by ned.deily. This issue is now closed.

Messages (3)
msg135867 - (view) Author: Atamurad Hezretkuliyev (atamyrat) Date: 2011-05-12 21:11
Parsing "<test xmlns=''></test>" with minidom and converting back to string raises an exception.

>>> import xml.dom.minidom
>>> xml.dom.minidom.parseString("<test xmlns=''></test>").toxml()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/minidom.py", line 45, in toxml
    return self.toprettyxml("", "", encoding)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/minidom.py", line 57, in toprettyxml
    self.writexml(writer, "", indent, newl, encoding)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/minidom.py", line 1749, in writexml
    node.writexml(writer, indent, addindent, newl)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/minidom.py", line 812, in writexml
    _write_data(writer, attrs[a_name].value)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/minidom.py", line 301, in _write_data
    data = data.replace("&", "&amp;").replace("<", "&lt;")
AttributeError: 'NoneType' object has no attribute 'replace'
>>> 

Ii am not familiar with the XML spec so I've no idea if ignoring or accepting empty namespace is the right thing to do. If someone advices me on how it should be handled, I'd like to write a patch.
msg221391 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-24 03:02
This works perfectly for me using 3.4.1.
msg221399 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014-06-24 06:38
This problem was fixed in Python 2.7.1 by b71aaf4e7d8d for Issue5762.
History
Date User Action Args
2014-06-24 06:38:30ned.deilysetstatus: open -> closed

superseder: AttributeError: 'NoneType' object has no attribute 'replace'
versions: + Python 2.7, - Python 2.6
nosy: + ned.deily

messages: + msg221399
resolution: duplicate
stage: resolved
2014-06-24 03:02:40BreamoreBoysetnosy: + BreamoreBoy
messages: + msg221391
2011-05-13 08:02:24ezio.melottisetnosy: + ezio.melotti
2011-05-12 21:11:15atamyratcreate