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

Skip Montanaro skip@mojam.com (Skip Montanaro)
Wed, 16 Aug 2000 23:04:54 -0500 (CDT)


>>>>> "Mark" == Mark Hammond <MarkH@ActiveState.com> writes:

    Mark> I believe that Skip recently made a patch to os.path.commonprefix
    Mark> to only return the portion of the common prefix that corresponds
    Mark> to a directory.

    Mark> I have just dicovered some code breakage from this change.  On
    Mark> 1.5.2, the behaviour was:

    >>>> os.path.commonprefix(["../foo/bar", "../foo/spam"])
    Mark> '../foo/'

    Mark> While since the change we have:
    Mark> '../foo'

I'm sure it can be argued that the slash should be there.  The previous
behavior was clearly broken, however, because it was advancing
character-by-character instead of directory-by-directory.  Consequently,
calling 

    os.path.commonprefix(["/home/swen", "/home/swenson"])

would yield the most likely invalid path "/home/sw" as the common prefix.

It would be easy enough to append the appropriate path separator to the the
result before returning.  I have no problem with that.  Others with more
knowledge of path semantics should chime in.  Also, should the behavior be
consistent across platforms or should it do what is correct for each
platform on which it's implemented (dospath, ntpath, macpath)?

Skip