summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_minidom.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-08-23 12:23:41 (GMT)
committerGitHub <noreply@github.com>2023-08-23 12:23:41 (GMT)
commit154477be722ae5c4e18d22d0860e284006b09c4f (patch)
tree04df1403a74ed9d464574298db337f81b370b074 /Lib/test/test_minidom.py
parent29bc6165ab8aa434145a34676b8b7e48e7c6e308 (diff)
downloadcpython-154477be722ae5c4e18d22d0860e284006b09c4f.zip
cpython-154477be722ae5c4e18d22d0860e284006b09c4f.tar.gz
cpython-154477be722ae5c4e18d22d0860e284006b09c4f.tar.bz2
gh-50002: xml.dom.minidom now preserves whitespaces in attributes (GH-107947)
Also double quotes (") are now only quoted in attributes.
Diffstat (limited to 'Lib/test/test_minidom.py')
-rw-r--r--Lib/test/test_minidom.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py
index 699265c..3ecd1af 100644
--- a/Lib/test/test_minidom.py
+++ b/Lib/test/test_minidom.py
@@ -505,6 +505,46 @@ class MinidomTest(unittest.TestCase):
dom.unlink()
self.confirm(str == domstr)
+ def test_toxml_quote_text(self):
+ dom = Document()
+ elem = dom.appendChild(dom.createElement('elem'))
+ elem.appendChild(dom.createTextNode('&<>"'))
+ cr = elem.appendChild(dom.createElement('cr'))
+ cr.appendChild(dom.createTextNode('\r'))
+ crlf = elem.appendChild(dom.createElement('crlf'))
+ crlf.appendChild(dom.createTextNode('\r\n'))
+ lflf = elem.appendChild(dom.createElement('lflf'))
+ lflf.appendChild(dom.createTextNode('\n\n'))
+ ws = elem.appendChild(dom.createElement('ws'))
+ ws.appendChild(dom.createTextNode('\t\n\r '))
+ domstr = dom.toxml()
+ dom.unlink()
+ self.assertEqual(domstr, '<?xml version="1.0" ?>'
+ '<elem>&amp;&lt;&gt;"'
+ '<cr>\r</cr>'
+ '<crlf>\r\n</crlf>'
+ '<lflf>\n\n</lflf>'
+ '<ws>\t\n\r </ws></elem>')
+
+ def test_toxml_quote_attrib(self):
+ dom = Document()
+ elem = dom.appendChild(dom.createElement('elem'))
+ elem.setAttribute("a", '&<>"')
+ elem.setAttribute("cr", "\r")
+ elem.setAttribute("lf", "\n")
+ elem.setAttribute("crlf", "\r\n")
+ elem.setAttribute("lflf", "\n\n")
+ elem.setAttribute("ws", "\t\n\r ")
+ domstr = dom.toxml()
+ dom.unlink()
+ self.assertEqual(domstr, '<?xml version="1.0" ?>'
+ '<elem a="&amp;&lt;&gt;&quot;" '
+ 'cr="&#13;" '
+ 'lf="&#10;" '
+ 'crlf="&#13;&#10;" '
+ 'lflf="&#10;&#10;" '
+ 'ws="&#9;&#10;&#13; "/>')
+
def testAltNewline(self):
str = '<?xml version="1.0" ?>\n<a b="c"/>\n'
dom = parseString(str)