Skip to content

plistlib inherits expat's newline-normalizing behavior, which can corrupt data in XML plists #139423

@glyph

Description

@glyph

Bug report

Bug description:

This is just a special case of #84561 but it came up in the specific circumstance of XML plists in MOPUp, here: https://github.com/glyph/MOPUp/pull/448/files#r2280646662

I also discovered that it is possible to get the unmodified data, by changing plistlib._PlistParser.handle_data to look like this:

    def handle_data(self, data):
        ctx = self.parser.GetInputContext()
        if data == '\n' and ctx[0:1] != b'\n':
            data = ctx[0:1].decode("utf-8")
        self.data.append(data)

so we are not totally bound by the whims of Expat here; these types of bug could be fixed.

CPython versions tested on:

3.12, 3.13, 3.11

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions