From 2ad5421dad86bc95aabe5c77f6034ee6ca699992 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 31 Aug 2014 09:34:09 -0400 Subject: [PATCH] don't index outside of the path (closes #22312) --- Lib/ntpath.py | 2 +- Lib/test/test_ntpath.py | 1 + Misc/NEWS | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 228bbb3f52..fcaf21b6b7 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -113,7 +113,7 @@ def splitdrive(p): """ if len(p) > 1: normp = p.replace(altsep, sep) - if (normp[0:2] == sep*2) and (normp[2] != sep): + if (normp[0:2] == sep*2) and (normp[2:3] != sep): # is a UNC path: # vvvvvvvvvvvvvvvvvvvv drive letter or UNC path # \\machine\mountpoint\directory\etc\... diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 78af18c621..7b5f7bb28c 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -50,6 +50,7 @@ class TestNtpath(unittest.TestCase): # Issue #19911: UNC part containing U+0130 self.assertEqual(ntpath.splitdrive(u'//conky/MOUNTPOİNT/foo/bar'), (u'//conky/MOUNTPOİNT', '/foo/bar')) + self.assertEqual(ntpath.splitdrive("//"), ("", "//")) def test_splitunc(self): tester('ntpath.splitunc("c:\\foo\\bar")', diff --git a/Misc/NEWS b/Misc/NEWS index 5d800347f4..d139e7b9d6 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -19,6 +19,8 @@ Core and Builtins Library ------- +- Issue #22312: Fix ntpath.splitdrive IndexError. + - Issue #22216: smtplib now resets its state more completely after a quit. The most obvious consequence of the previous behavior was a STARTTLS failure during a connect/starttls/quit/connect/starttls sequence. -- 2.50.1