summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-10-15 17:58:45 +0000
committerGeorg Brandl <georg@python.org>2010-10-15 17:58:45 +0000
commit1ea2e09968e1ff91de9faabb13a348109d6b365e (patch)
tree18bbbb65563c7ec17510bc4f7a2afc023a8b91f1
parente92c32716d385919b4ecd80293f0434e317bcd3f (diff)
downloadcpython-1ea2e09968e1ff91de9faabb13a348109d6b365e.tar.gz
#5762: fix handling of empty namespace in minidom, which would result in AttributeError on toxml().
-rw-r--r--Lib/test/test_minidom.py7
-rw-r--r--Lib/xml/dom/minidom.py7
-rw-r--r--Misc/NEWS3
3 files changed, 14 insertions, 3 deletions
diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py
index d9d3be49c8..97668d343c 100644
--- a/Lib/test/test_minidom.py
+++ b/Lib/test/test_minidom.py
@@ -1489,6 +1489,13 @@ class MinidomTest(unittest.TestCase):
doc.appendChild(doc.createComment("foo--bar"))
self.assertRaises(ValueError, doc.toxml)
+ def testEmptyXMLNSValue(self):
+ doc = parseString("<element xmlns=''>\n"
+ "<foo/>\n</element>")
+ doc2 = parseString(doc.toxml())
+ self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
+
+
def test_main():
run_unittest(MinidomTest)
diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py
index 1beae0cffa..81a1330c60 100644
--- a/Lib/xml/dom/minidom.py
+++ b/Lib/xml/dom/minidom.py
@@ -301,9 +301,10 @@ def _in_document(node):
def _write_data(writer, data):
"Writes datachars to writer."
- data = data.replace("&", "&amp;").replace("<", "&lt;")
- data = data.replace("\"", "&quot;").replace(">", "&gt;")
- writer.write(data)
+ if data:
+ data = data.replace("&", "&amp;").replace("<", "&lt;"). \
+ replace("\"", "&quot;").replace(">", "&gt;")
+ writer.write(data)
def _get_elements_by_tagName_helper(parent, name, rc):
for node in parent.childNodes:
diff --git a/Misc/NEWS b/Misc/NEWS
index 097edd20ee..4bb89da9a6 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,6 +24,9 @@ Core and Builtins
Library
-------
+- Issue #5762: Fix AttributeError raised by ``xml.dom.minidom`` when an empty
+ XML namespace attribute is encountered.
+
- Issue #2830: Add the ``html.escape()`` function, which quotes all problematic
characters by default. Deprecate ``cgi.escape()``.