New submission from Petr Prikryl <prik...@atlas.cz>:
When ElementTree object is to be written to the file, and when BOM is needed, the 'utf-8-sig' can be used for the purpose. However, the XML prolog then looks like... <?xml version='1.0' encoding='utf-8-sig'?> ... and that encoding in the prolog makes no sense. Therefore, the utf-8-sig is changed to utf-8 for the purpose. To fix the situation, the following two lines should be added to `cpython/Lib/xml/etree/ElementTree.py` `elif enc_lower == "utf-8-sig": declared_encoding = "utf-8" ` just above the line 741 that says `write("<?xml version='1.0' encoding='%s'?>\n" % ( declared_encoding,))` I have already cloned the main branch, added the lines to `https://github.com/pepr/cpython.git`, and sent pull request. I have tested the functionality locally with `Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32` ---------- components: Library (Lib) messages: 412247 nosy: prikryl priority: normal pull_requests: 29231 severity: normal status: open title: ElementTree: wrong XML prolog for the utf-8-sig encoding versions: Python 3.10 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue46598> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com