You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Activity
eljay451 commentedon Mar 14, 2008
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:
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.
abalkin commentedon Mar 16, 2008
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 .
birkenfeld commentedon Mar 16, 2008
Closing as "Won't fix".