Skip to content

os.path.normpath over-normalizes #46542

Description

@eljay451
mannequin
BPO 2289
Nosy @birkenfeld, @abalkin

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 2008-03-16.21:53:19.689>
created_at = <Date 2008-03-14.18:43:44.486>
labels = ['type-feature']
title = 'os.path.normpath over-normalizes'
updated_at = <Date 2008-03-16.21:53:19.687>
user = 'https://bugs.python.org/eljay451'

bugs.python.org fields:

activity = <Date 2008-03-16.21:53:19.687>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = <Date 2008-03-16.21:53:19.689>
closer = 'georg.brandl'
components = []
creation = <Date 2008-03-14.18:43:44.486>
creator = 'eljay451'
dependencies = []
files = []
hgrepos = []
issue_num = 2289
keywords = []
message_count = 3.0
messages = ['63533', '63586', '63605']
nosy_count = 3.0
nosy_names = ['georg.brandl', 'belopolsky', 'eljay451']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue2289'
versions = ['Python 2.4']

Activity

  1. eljay451 commented on Mar 14, 2008

    eljay451mannequin
    MannequinAuthor

    I found a bug (or at least a shortcoming) in Python's os.path.normpath routine.

    It overly normalizes, at least for Unix and Unix-like systems (including Mac), and
    Windows.

    Example:

    x = os.path.join(".", "dog", "..", "cupcake.txt")
    print x
    x = os.path.normpath(x)
    print x

    If say "dog" is a symlink (any flavor of Unix (including OS X), or Win), there is a
    difference between ./dog/../cupcake.txt and ./cupcake.txt.

    In the OS, if dog is a symlink to fire/fly, the .. resolves relative to fire/fly.

    It should be safe to normalize this:
    ././././././././cupcake.txt --> ./cupcake.txt

    It should be safe to normalize this:
    .////////////////cupcake.txt --> ./cupcake.txt

    But this is not safe to normalize:
    ./x/../x/../x/../cupcake.txt --> ./cupcake.txt

    For example, if the directories look like this:
    ./cupcake.txt
    ./over/yonder/back/cupcake.txt
    ./x --> over/there
    ./over/there
    ./over/x --> yonder/aways
    ./over/yonder/aways
    ./over/yonder/x --> back/again
    ./over/yonder/back/again

    ./cupcake.txt refers to first cupcake.
    ./x/../x/../x/../cupcake.txt refers to the second cupcake.

    The os.path.realpath does the resolve, but sometimes the path-in-hand is for some
    arbitrary path, and not necessarily one on the local system, or if on the local
    files system may be relative based off from a different cwd.

  2. abalkin commented on Mar 16, 2008

    @abalkin
    Member

    This is a documented feature:

    """
    normpath(path)

    Normalize a pathname. ... It should be understood that this may change
    the meaning of the path if it contains symbolic links!
    """

    See http://docs.python.org/lib/module-os.path.html .

  3. added
    type-featureA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or error
    on Mar 16, 2008
  4. birkenfeld commented on Mar 16, 2008

    @birkenfeld
    Member

    Closing as "Won't fix".

  5. transferred this issue fromon Apr 10, 2022
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

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions