Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.path.abspath() needs more normalization on Windows #90520

Closed
neonene mannequin opened this issue Jan 13, 2022 · 7 comments
Closed

os.path.abspath() needs more normalization on Windows #90520

neonene mannequin opened this issue Jan 13, 2022 · 7 comments
Labels
3.11 only security fixes OS-windows type-bug An unexpected behavior, bug, or error

Comments

@neonene
Copy link
Mannequin

neonene mannequin commented Jan 13, 2022

BPO 46362
Nosy @pfmoore, @ericvsmith, @tjguk, @zware, @zooba, @neonene
PRs
  • bpo-46362: Ensure ntpath.abspath() calls Windows API #30571
  • bpo-46362: Make abspath() test available for Windows PGO #30595
  • 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 = <Date 2022-01-13.23:38:14.076>
    created_at = <Date 2022-01-13.03:08:54.643>
    labels = ['type-bug', 'OS-windows', '3.11']
    title = 'os.path.abspath() needs more normalization on Windows'
    updated_at = <Date 2022-01-14.15:31:47.572>
    user = 'https://github.com/neonene'

    bugs.python.org fields:

    activity = <Date 2022-01-14.15:31:47.572>
    actor = 'steve.dower'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-13.23:38:14.076>
    closer = 'steve.dower'
    components = ['Windows']
    creation = <Date 2022-01-13.03:08:54.643>
    creator = 'neonene'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46362
    keywords = ['patch']
    message_count = 7.0
    messages = ['410456', '410482', '410491', '410532', '410533', '410534', '410568']
    nosy_count = 6.0
    nosy_names = ['paul.moore', 'eric.smith', 'tim.golden', 'zach.ware', 'steve.dower', 'neonene']
    pr_nums = ['30571', '30595']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46362'
    versions = ['Python 3.11']

    @neonene
    Copy link
    Mannequin Author

    neonene mannequin commented Jan 13, 2022

    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.

    @neonene neonene mannequin added 3.11 only security fixes OS-windows type-bug An unexpected behavior, bug, or error labels Jan 13, 2022
    @ericvsmith
    Copy link
    Member

    Can you show various paths, before and after your change? It’s not clear to me what you’re proposing to change.

    @neonene
    Copy link
    Mannequin Author

    neonene mannequin commented Jan 13, 2022

    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
    """

    @zooba
    Copy link
    Member

    zooba commented Jan 13, 2022

    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.

    @zooba
    Copy link
    Member

    zooba commented Jan 13, 2022

    New changeset d4e64cd by neonene in branch 'main':
    bpo-46362: Ensure ntpath.abspath() uses the Windows API correctly (GH-30571)
    d4e64cd

    @zooba
    Copy link
    Member

    zooba commented Jan 13, 2022

    Thanks for the patch!

    @zooba zooba closed this as completed Jan 13, 2022
    @zooba zooba closed this as completed Jan 13, 2022
    @zooba
    Copy link
    Member

    zooba commented Jan 14, 2022

    New changeset 71c0b85 by neonene in branch 'main':
    bpo-46362: Ensure abspath() tests pass through environment variables to subprocess (GH-30595)
    71c0b85

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes OS-windows type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants