Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-50002: xml.dom.minidom now preserves whitespaces in attributes#107947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
dd6c84c6dd15a4b926f36dc72044File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Also double quotes (") are now only quoted in attributes.- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -505,6 +505,46 @@ def testWriteXML(self): | ||
| 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>&<>"' | ||
| '<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="&<>"" ' | ||
| 'cr=" " ' | ||
| 'lf=" " ' | ||
| 'crlf=" " ' | ||
| 'lflf=" " ' | ||
| 'ws="	 "/>') | ||
serhiy-storchaka marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| def testAltNewline(self): | ||
| str = '<?xml version="1.0" ?>\n<a b="c"/>\n' | ||
| dom = parseString(str) | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -300,12 +300,27 @@ def _in_document(node): | ||||||||
| node = node.parentNode | ||||||||
| return False | ||||||||
| def _write_data(writer,text, attr): | ||||||||
scoder marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||||
| "Writes datachars to writer." | ||||||||
| if text: | ||||||||
| ||||||||
| iftext: | |
| ifnottext: | |
| return |
rather than adding indentation to long chunks of code that only makes readers look down to see if something joined is still done at the end. Better make it clear right away that we're done handling this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Agree. I just kept the style of the old code.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| :mod:`xml.dom.minidom` now preserves whitespaces in attributes. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| :mod:`xml.dom.minidom` now only quotes ``"`` in attributes. |