classification
Title: ElementTree corrupts cAse of closing tags when html method is specified
Type: behavior Stage: resolved
Components: XML Versions: Python 3.4, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Adam.Urban, christian.heimes, eli.bendersky, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2013-07-02 17:31 by Adam.Urban, last changed 2013-07-04 23:42 by christian.heimes. This issue is now closed.

Files
File name Uploaded Description Edit
18347_taglower.patch christian.heimes, 2013-07-02 21:06 review
Messages (5)
msg192212 - (view) Author: Adam Urban (Adam.Urban) Date: 2013-07-02 17:31
import xml.etree.ElementTree as ET
tree = ET.parse("myinput.xml")
tree.write("myoutput.xml", encoding="utf-16le", xml_declaration=False, default_namespace=None, method="html")

If the source XML has a tag like this:
<someTag>someData</someTag>

ElementTree will output it like this when html is specified as the "method":

<someTag>someData</sometag>
msg192216 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-07-02 20:42
I'm able to confirm the issue for Python 2.7 and 3.x:

>>> import xml.etree.ElementTree as ET
>>> tree = ET.fromstring("<someTag>someData</someTag>")
>>> ET.tostring(tree, encoding="utf-8", method="html")
b'<someTag>someData</sometag>'
msg192217 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-07-02 21:06
Attached fix with unit test

The HTML serializer has a line tag = tag.lower() and used the lower tag to write the end tag.
msg192227 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-07-03 10:32
LGTM. Please add a reference to this issue in the test.
msg192323 - (view) Author: Roundup Robot (python-dev) Date: 2013-07-04 23:41
New changeset df79735b21c1 by Christian Heimes in branch '3.3':
Issue #18347: ElementTree's html serializer now preserves the case of closing tags.
http://hg.python.org/cpython/rev/df79735b21c1

New changeset d5536c06a082 by Christian Heimes in branch 'default':
Issue #18347: ElementTree's html serializer now preserves the case of closing tags.
http://hg.python.org/cpython/rev/d5536c06a082

New changeset 328781ae35d2 by Christian Heimes in branch '2.7':
Issue #18347: ElementTree's html serializer now preserves the case of closing tags.
http://hg.python.org/cpython/rev/328781ae35d2
History
Date User Action Args
2013-07-04 23:42:23christian.heimessetstatus: open -> closed
resolution: fixed
stage: needs patch -> resolved
2013-07-04 23:41:50python-devsetnosy: + python-dev
messages: + msg192323
2013-07-03 10:32:37serhiy.storchakasetmessages: + msg192227
2013-07-02 21:06:01christian.heimessetfiles: + 18347_taglower.patch
keywords: + patch
messages: + msg192217
2013-07-02 20:42:10christian.heimessetversions: - Python 2.6, Python 3.1, Python 3.5
nosy: + christian.heimes

messages: + msg192216

stage: needs patch
2013-07-02 17:31:39Adam.Urbancreate