[Python-bugs-list] [ python-Bugs-749261 ] os.path.split does not handle . & .. properly
SourceForge.net
noreply@sourceforge.net
Wed, 04 Jun 2003 18:03:01 -0700
Bugs item #749261, was opened at 2003-06-04 18:03
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=749261&group_id=5470
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Curtis Siemens (csiemens)
Assigned to: Nobody/Anonymous (nobody)
Summary: os.path.split does not handle . & .. properly
Initial Comment:
The os.path.split() & posixpath.split() functions in my
opinion do not handle '.' & '..' at the end of a path
properly which causes os.path.dirname() &
os.path.basename() to also return the wrong result
because they are directly based on os.path.split().
I'll demonstrate the Unix Python case (the Windows
ntpath.py case is just a close parallel variation).
Example:
>python
Python 2.1.1
>>> posixpath.split('.')
('', '.')
>>> posixpath.split('..')
('', '..')
Yet:
>>> posixpath.split('./')
('..', '')
>>> posixpath.split('../')
('..', '')
Now '.' really represents './', and '..' really
represents '../'
Since the split() function simply uses a string split
on '/' to
find directories, it goofs up on this one case. The
'.' and
'..' are like the slash character in the sense that
they all
only refer to directories.
The '.' & '..' can never be files in Unix or Windows, so I
think that the split() function should treat paths like:
.
..
dir/.
dir/..
/dir1/dir2/.
/dir1/dir2/..
as not having a file portion, just as if:
./
../
dir/./
dir/../
/dir1/dir2/./
/dir1/dir2/../
respectively were given instead.
The fix in posixpath.py for this is just to put a
little path
processing code at the beginning of the split() function
that looks for the follow cases:
if p in ['.','..'] or p[-2:] == '/.' or p[-3:] ==
'/..':
p = p+'/'
And then go into all the regular split() code.
In fix in ntpath.py is very similar.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=749261&group_id=5470