Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-117201: Handle leading// forposixpath.commonpath#117202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
nineteendo wants to merge14 commits intopython:mainfromnineteendo:fix-commonpath
Closed
Show file tree
Hide file tree
Changes from2 commits
Commits
Show all changes
14 commits
Select commitHold shift + click to select a range
247c9af
Handle leading `//` for `posixpath.commonpath`
nineteendoMar 24, 2024
0c38276
raise TypeError for non-sequences
nineteendoMar 24, 2024
a9b0832
📜🤖 Added by blurb_it.
blurb-it[bot]Mar 26, 2024
a521282
Remove `break` & `else`
nineteendoMar 26, 2024
b467e7e
Merge branch 'fix-commonpath' of https://github.com/nineteendo/cpytho…
nineteendoMar 26, 2024
26eac21
Handle errors for iterable
nineteendoMar 26, 2024
d83743d
Remove redundant check
nineteendoMar 27, 2024
1ae0c43
raise TypeError for non-sequences
nineteendoMar 28, 2024
e6de234
Update NEWS.d
nineteendoMar 28, 2024
012c12e
Add newline
nineteendoMar 28, 2024
fb1c91a
Speed up `posixpath.ismount`
nineteendoMar 28, 2024
ca90fde
unnest `posixpath.expanduser`
nineteendoMar 28, 2024
758e0d6
Speed up `posixpath.expanduser` & `posixpath.normpath`
nineteendoMar 28, 2024
218e43e
Move refactoring to new branch
nineteendoMar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletionsLib/posixpath.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -545,38 +545,36 @@ def relpath(path, start=None):

def commonpath(paths):
"""Given a sequence of path names, returns the longest common sub-path."""
_, roots, tails = zip(*map(splitroot, paths))
if not roots:
raise ValueError('commonpath() arg is an empty sequence')

paths = tuple(map(os.fspath, paths))
try:
prefix = min(roots)
except (TypeError, AttributeError):
genericpath._check_arg_types('commonpath', *paths)
raise

if notpaths:
raise ValueError('commonpath() arg is an empty sequence')
if notprefix and max(roots):
raise ValueError("Can't mix absolute and relative paths")

if isinstance(paths[0], bytes):
if isinstance(prefix, bytes):
sep = b'/'
curdir = b'.'
else:
sep = '/'
curdir = '.'

try:
split_paths = [path.split(sep) for path in paths]

try:
isabs, = set(p[:1] == sep for p in paths)
except ValueError:
raise ValueError("Can't mix absolute and relative paths") from None

split_paths = [[c for c in s if c and c != curdir] for s in split_paths]
s1 = min(split_paths)
s2 = max(split_paths)
split_paths = [
[c for c in tail.split(sep) if c and c != curdir] for tail in tails
]
s1 = min(split_paths)
s2 = max(split_paths)
for i, c in enumerate(s1):
if c != s2[i]:
common = s1[:i]
break
else:
common = s1
for i, c in enumerate(s1):
if c != s2[i]:
common = s1[:i]
break

prefix = sep if isabs else sep[:0]
return prefix + sep.join(common)
except (TypeError, AttributeError):
genericpath._check_arg_types('commonpath', *paths)
raise
return prefix + sep.join(common)
3 changes: 3 additions & 0 deletionsLib/test/test_posixpath.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -749,6 +749,9 @@ def check_error(exc, paths):
self.assertRaises(TypeError, posixpath.commonpath,
['usr/lib/', b'/usr/lib/python3'])

# gh-117201: `posixpath.commonpath` doesn't handle leading `//` properly
check(['//foo/bar', '//foo/baz'], '//foo')


class PosixCommonTest(test_genericpath.CommonTest, unittest.TestCase):
pathmodule = posixpath
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp