[Python-checkins] r85546 - in python/branches/py3k: Lib/test/test_minidom.py Lib/xml/dom/minidom.py Misc/NEWS

georg.brandl python-checkins at python.org
Fri Oct 15 19:58:45 CEST 2010


Author: georg.brandl
Date: Fri Oct 15 19:58:45 2010
New Revision: 85546
Log:
#5762: fix handling of empty namespace in minidom, which would result in AttributeError on toxml().
Modified:
 python/branches/py3k/Lib/test/test_minidom.py
 python/branches/py3k/Lib/xml/dom/minidom.py
 python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/test/test_minidom.py
==============================================================================
--- python/branches/py3k/Lib/test/test_minidom.py	(original)
+++ python/branches/py3k/Lib/test/test_minidom.py	Fri Oct 15 19:58:45 2010
@@ -1489,6 +1489,13 @@
 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)
 
Modified: python/branches/py3k/Lib/xml/dom/minidom.py
==============================================================================
--- python/branches/py3k/Lib/xml/dom/minidom.py	(original)
+++ python/branches/py3k/Lib/xml/dom/minidom.py	Fri Oct 15 19:58:45 2010
@@ -301,9 +301,10 @@
 
 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:
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Fri Oct 15 19:58:45 2010
@@ -24,6 +24,9 @@
 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()``. 
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /