FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

ElementTree: wrong XML prolog for the utf-8-sig encoding · Issue #90756 · python/cpython · GitHub

Repository navigation

ElementTree: wrong XML prolog for the utf-8-sig encoding #90756

Closed

Description

mannequin
BPO 46598
Nosy @pepr, @scoder
PRs
  • gh-90756: Fix ElementTree.write XML prolog for encoding 'utf-8-sig' #31043
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2022-02-01.11:00:34.033>
    labels = ['library', '3.10', '3.11']
    title = 'ElementTree: wrong XML prolog for the utf-8-sig encoding'
    updated_at = <Date 2022-02-01.16:40:13.781>
    user = 'https://github.com/pepr'

    bugs.python.org fields:

    activity = <Date 2022-02-01.16:40:13.781>
    actor = 'ned.deily'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2022-02-01.11:00:34.033>
    creator = 'prikryl'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46598
    keywords = []
    message_count = 1.0
    messages = ['412247']
    nosy_count = 3.0
    nosy_names = ['prikryl', 'scoder', 'eli.bendersky']
    pr_nums = ['31043']
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46598'
    versions = ['Python 3.10', 'Python 3.11']

    Activity

    1. pepr commented on Feb 1, 2022

      peprmannequin
      MannequinAuthor

      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

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Feb 1, 2022
    3. transferred this issue fromon Apr 10, 2022
    4. added a commit that references this issue on Aug 13, 2026
    5. added
      type-featureA feature request or enhancement
      3.16new features, bugs and security fixes
      and removed
      3.11only security fixes
      on Aug 13, 2026
    6. added a commit that references this issue on Aug 14, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-XMLtype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions


        Back | FazBrowse Home | New Git URL