From cdbb595120cde9cced732de3ff10a4a6561b4ee2 Mon Sep 17 00:00:00 2001 From: Nineteendo Date: Fri, 29 Mar 2024 08:01:04 +0100 Subject: [PATCH 1/6] Handle `/:` for `ntpath.isabs` --- Lib/ntpath.py | 5 ++++- Lib/test/test_ntpath.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index ecfc7d48dbb192..f27d53530a4d32 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -93,7 +93,10 @@ def isabs(s): 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) + return ( + (s.startswith(colon_sep, 1) and not s.startswith(sep)) + or s.startswith(double_sep) + ) # Join two (or more) 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) From fec0a931f3baa8a876a945d46cb24dceb4631b83 Mon Sep 17 00:00:00 2001 From: Nineteendo Date: Fri, 29 Mar 2024 08:32:01 +0100 Subject: [PATCH 2/6] Speedup `ntpath.isabs` --- Lib/ntpath.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index f27d53530a4d32..dd9231f37bbeae 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -93,10 +93,7 @@ def isabs(s): double_sep = '\\\\' s = s[:3].replace(altsep, sep) # Absolute: UNC, device, and paths with a drive and root. - return ( - (s.startswith(colon_sep, 1) and not s.startswith(sep)) - or s.startswith(double_sep) - ) + return (s[1:3] == colon_sep and s[:1] != sep) or s[:2] == double_sep # Join two (or more) paths. From cf6286868878470329902c4c4aa29143523796ae Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 29 Mar 2024 07:34:40 +0000 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024-03-29-07-34-39.gh-issue-117352.-34fR4.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-03-29-07-34-39.gh-issue-117352.-34fR4.rst 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..67b41046929e96 --- /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`. From 2950921bc2f1dcaf73e8ad3711dd4b353136e440 Mon Sep 17 00:00:00 2001 From: Nineteendo Date: Sat, 30 Mar 2024 09:07:46 +0100 Subject: [PATCH 4/6] Simplify check Co-Authored-By: Barney Gale --- Lib/ntpath.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index dd9231f37bbeae..c6f88d9a4c99bf 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[1:3] == colon_sep and s[:1] != sep) or s[:2] == double_sep - + if s[:1] == sep: + return s[1:2] == sep + else: + return s[1:3] == colon_sep # Join two (or more) paths. def join(path, *paths): From 941c276302e8315474469e1fc73022a1466b9fe9 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Sun, 31 Mar 2024 11:57:31 +0200 Subject: [PATCH 5/6] Update 2024-03-29-07-34-39.gh-issue-117352.-34fR4.rst --- .../2024-03-29-07-34-39.gh-issue-117352.-34fR4.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 67b41046929e96..c84e3257da8b1e 100644 --- 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 @@ -1 +1 @@ -Handle ``/:`` for :func:`ntpath.isabs`. +Handle ``/:/`` for :func:`ntpath.isabs`. From 9abff6a54785ce85389c6ea9adcd3f108f499c2a Mon Sep 17 00:00:00 2001 From: Nineteendo Date: Mon, 1 Apr 2024 21:20:16 +0200 Subject: [PATCH 6/6] Revert `str.startswith()` --- Lib/ntpath.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index c6f88d9a4c99bf..c48fc1d5fa4db0 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -91,10 +91,10 @@ def isabs(s): colon_sep = ':\\' s = s[:3].replace(altsep, sep) # Absolute: UNC, device, and paths with a drive and root. - if s[:1] == sep: - return s[1:2] == sep + if s.startswith(sep): + return s.startswith(sep, 1) else: - return s[1:3] == colon_sep + return s.startswith(colon_sep, 1) # Join two (or more) paths. def join(path, *paths):