Skip to content

pathlib.PureWindowsPath comparison results vary between Windows and Posix #104947

Closed
@barneygale

Description

@barneygale

In #31691 I switched pathlib.PureWindowsPath comparisons to use os.path.normcase() rather than str.lower(). This is probably a mistake, as @eryksun points out:

The inconsistency is with ntpath.normcase() on Windows. It's probably for the best if the pure comparison methods revert to using str.lower() for the sake of consistency, not only with glob() and match(), but also with using PureWindowsPath on POSIX. Maybe platform-dependent comparisons could be implemented on Path.

On Windows, ntpath.normcase() is based on LCMapStringEx(). It turns out that this function implements a case mapping for some non-BMP characters. WinAPI CompareStringOrdinal(), on the other hand, has no case mapping for non-BMP characters, which is consistent with Microsoft's filesystems. Thus I'd prefer for a platform-dependent comparison to use CompareStringOrdinal() instead of LCMapStringEx().

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions