diff --git a/Lib/ntpath.py b/Lib/ntpath.py index ecfc7d48dbb192..c48fc1d5fa4db0 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -85,16 +85,16 @@ def isabs(s): sep = b'\\' altsep = b'/' colon_sep = b':\\' - double_sep = b'\\\\' else: sep = '\\' altsep = '/' colon_sep = ':\\' - double_sep = '\\\\' s = s[:3].replace(altsep, sep) # Absolute: UNC, device, and paths with a drive and root. - return s.startswith(colon_sep, 1) or s.startswith(double_sep) - + if s.startswith(sep): + return s.startswith(sep, 1) + else: + return s.startswith(colon_sep, 1) # Join two (or more) paths. def join(path, *paths): diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index c816f99e7e9f1b..029410774fc78d 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -234,11 +234,12 @@ def test_isabs(self): tester('ntpath.isabs("c:/foo/bar")', 1) tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1) - # gh-44626: paths with only a drive or root are not absolute. + # gh-44626 & gh-117352: paths with only a drive or root are not absolute. tester('ntpath.isabs("\\foo\\bar")', 0) tester('ntpath.isabs("/foo/bar")', 0) tester('ntpath.isabs("c:foo\\bar")', 0) tester('ntpath.isabs("c:foo/bar")', 0) + tester('ntpath.isabs("/:/foo/bar")', 0) # gh-96290: normal UNC paths and device paths without trailing backslashes tester('ntpath.isabs("\\\\conky\\mountpoint")', 1) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-03-29-07-34-39.gh-issue-117352.-34fR4.rst b/Misc/NEWS.d/next/Core and Builtins/2024-03-29-07-34-39.gh-issue-117352.-34fR4.rst new file mode 100644 index 00000000000000..c84e3257da8b1e --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-03-29-07-34-39.gh-issue-117352.-34fR4.rst @@ -0,0 +1 @@ +Handle ``/:/`` for :func:`ntpath.isabs`.