Skip to content

os.path.commonprefix returns insane results #158994

Description

@darryldixon

Bug report

>>> os.path.commonprefix(('root/blah', 'rawr/oaeu'))
'r'
>>> os.path.commonprefix(('/root/blah', '/rawr/oaeu'))
'/r'
>>> 

This is clearly not a sane result.

To be clear, a sane result would look like
''
for the first example, and
'/'
for the second example.

This would then be consistent with how the module behaves for other examples:

os.path.commonprefix(('/root/blah', '/root/oaeu'))
'/root/'

This is also insane:

os.path.commonprefix(('/root/blah', '/root/baeu'))
'/root/b'

os.path.commonprefix(('/root/blah', '/root/baeu'))
'/root/b'

The returned example is not a "path". It is not a 'path prefix' in any meaningful sense. This is just a string match up to the point the string changes. It has nothing whatsoever to do with the notion of a 'path'.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions