Skip to content

Commit c52518f

Browse files
committed
Fix ElementTree.write XML prolog for encoding 'utf-8-sig'
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.
1 parent ee0ac32 commit c52518f

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

Lib/xml/etree/ElementTree.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ def write(self, file_or_filename,
738738
# Retrieve the default encoding for the xml declaration
739739
import locale
740740
declared_encoding = locale.getpreferredencoding()
741+
elif enc_lower == "utf-8-sig":
742+
declared_encoding = "utf-8"
741743
write("<?xml version='1.0' encoding='%s'?>\n" % (
742744
declared_encoding,))
743745
if method == "text":

0 commit comments

Comments
 (0)