[Python-Dev] Re: os.path.commonprefix breakage

M.-A. Lemburg mal@lemburg.com
Thu, 17 Aug 2000 09:31:55 +0200


Skip Montanaro wrote:
> 
>     Fred> I'd guess that the path separator should only be appended if it's
>     Fred> part of the passed-in strings; that would make it a legitimate
>     Fred> part of the prefix.  If it isn't present for all of them, it
>     Fred> shouldn't be part of the result:
> 
>     >>> os.path.commonprefix(["foo", "foo/bar"])
>     'foo'
> 
> Hmmm... I think you're looking at it character-by-character again.  I see
> three possibilities:
> 
>     * it's invalid to have a path with a trailing separator
> 
>     * it's okay to have a path with a trailing separator
> 
>     * it's required to have a path with a trailing separator
> 
> In the first and third cases, you have no choice.  In the second you have to
> decide which would be best.
> 
> On Unix my preference would be to not include the trailing "/" for aesthetic
> reasons.

Wait, Skip :-) By dropping the trailing slash from the path
you are removing important information from the path information.

This information can only be regained by performing an .isdir()
check and then only of the directory exists somewhere. If it
doesn't you are loosing valid information here.

Another aspect: 
Since posixpath is also used by URL handling code,
I would suspect that this results in some nasty problems too.
You'd have to actually ask the web server to give you back the
information you already had.

Note that most web-servers send back a redirect in case a
directory is queried without ending slash in the URL. They
do this for exactly the reason stated above: to add the
.isdir() information to the path itself.

Conclusion:
Please don't remove the slash -- at least not in posixpath.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/