[New-bugs-announce] [issue2289] os.path.normpath over-normalizes

John Love-Jensen report at bugs.python.org
Fri Mar 14 19:43:45 CET 2008

New submission from John Love-Jensen <eljay at adobe.com>:

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 


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:
./x --> over/there
./over/x --> yonder/aways
./over/yonder/x --> 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.

messages: 63533
nosy: eljay451
severity: minor
status: open
title: os.path.normpath over-normalizes
type: behavior
versions: Python 2.4

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list