classification
Title: os.path.abspath() needs more normalization on Windows
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, neonene, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: patch

Created on 2022-01-13 03:08 by neonene, last changed 2022-01-14 15:31 by steve.dower. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30571 merged neonene, 2022-01-13 03:12
PR 30595 merged neonene, 2022-01-14 09:20
Messages (7)
msg410456 - (view) Author: neonene (neonene) * Date: 2022-01-13 03:08
3.11a3+ introduced the C version of abspath(), which shows incompletely normalized absolute path (see msg410068):

    >>> os.path.abspath(r'\\spam\\eggs. . .')
    '\\\\spam\\\\eggs. . .'
    >>> os.path.abspath('C:\\spam. . .')
    'C:\\spam. . .'
    >>> os.path.abspath('C:\\nul')
    'C:\\nul'

The design is efficient on startup with getpath_abspath(), but ntpath.abspath()'s result after startup should be more normalized.
msg410482 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-13 10:24
Can you show various paths, before and after your change? It’s not clear to me what you’re proposing to change.
msg410491 - (view) Author: neonene (neonene) * Date: 2022-01-13 13:30
Basically, PR30571 aims for compatibility with 3.10 and earlier. Using Windows API is the easiest and the same way as them:

import os.path
paths = [
    r'C:\CON',
    r'C:\PRN',
    r'C:\AUX',
    r'C:\NUL',
    r'C:\COM1',
    r'C:\COM2',
    r'C:\COM3',
    r'C:\COM9',
    r'C:\LPT1',
    r'C:\LPT2',
    r'C:\LPT3',
    r'C:\LPT9',
    r'C:\foo. . .',
]
for path in paths:
    print(os.path.abspath(path))

"""
3.11 before
    C:\CON
    C:\PRN
    C:\AUX
    C:\NUL
    C:\COM1
    C:\COM2
    C:\COM3
    C:\COM9
    C:\LPT1
    C:\LPT2
    C:\LPT3
    C:\LPT9
    C:\foo. . .

3.11 after
    \\.\CON
    \\.\PRN
    \\.\AUX
    \\.\NUL
    \\.\COM1
    \\.\COM2
    \\.\COM3
    \\.\COM9
    \\.\LPT1
    \\.\LPT2
    \\.\LPT3
    \\.\LPT9
    C:\foo

3.10.1
    \\.\CON
    \\.\PRN
    \\.\AUX
    \\.\NUL
    \\.\COM1
    \\.\COM2
    \\.\COM3
    \\.\COM9
    \\.\LPT1
    \\.\LPT2
    \\.\LPT3
    \\.\LPT9
    C:\foo
"""
msg410532 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-01-13 23:33
One thing to be aware of is that Windows 11 has changed the rules around these files, so here's my results with 3.10:

>>> for path in paths:
...     print(os.path.abspath(path))
...
C:\CON
C:\PRN
C:\AUX
\\.\NUL
C:\COM1
C:\COM2
C:\COM3
C:\COM9
C:\LPT1
C:\LPT2
C:\LPT3
C:\LPT9
C:\foo

But this shouldn't be an issue with the proposed (about to be merged) change.
msg410533 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-01-13 23:35
New changeset d4e64cd4b0ea431d4e371f9b0a25f6b75a069dc1 by neonene in branch 'main':
bpo-46362: Ensure ntpath.abspath() uses the Windows API correctly (GH-30571)
https://github.com/python/cpython/commit/d4e64cd4b0ea431d4e371f9b0a25f6b75a069dc1
msg410534 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-01-13 23:38
Thanks for the patch!
msg410568 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-01-14 15:31
New changeset 71c0b859ae16ee748cbb050a1f4de93c04e04f83 by neonene in branch 'main':
bpo-46362: Ensure abspath() tests pass through environment variables to subprocess (GH-30595)
https://github.com/python/cpython/commit/71c0b859ae16ee748cbb050a1f4de93c04e04f83
History
Date User Action Args
2022-01-14 15:31:47steve.dowersetmessages: + msg410568
2022-01-14 09:20:26neonenesetpull_requests: + pull_request28793
2022-01-13 23:38:14steve.dowersetstatus: open -> closed
resolution: fixed
messages: + msg410534

stage: patch review -> resolved
2022-01-13 23:35:46steve.dowersetmessages: + msg410533
2022-01-13 23:33:51steve.dowersetmessages: + msg410532
2022-01-13 13:30:57neonenesetmessages: + msg410491
2022-01-13 10:24:02eric.smithsetnosy: + eric.smith
messages: + msg410482
2022-01-13 03:12:35neonenesetkeywords: + patch
stage: patch review
pull_requests: + pull_request28772
2022-01-13 03:08:54neonenecreate