diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-12-16 13:15:29 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-12-16 13:15:29 (GMT) |
commit | dd5a46c696a127a947e015741c4565878d72b3d4 (patch) | |
tree | a4b3468e08c9aff21c29371c7964127b73649da9 /Lib/ntpath.py | |
parent | d1a61dcc65a85639f273b31fd32267092db9a06e (diff) | |
download | cpython-dd5a46c696a127a947e015741c4565878d72b3d4.zip cpython-dd5a46c696a127a947e015741c4565878d72b3d4.tar.gz cpython-dd5a46c696a127a947e015741c4565878d72b3d4.tar.bz2 |
Issue #19912: Fixed numerous bugs in ntpath.splitunc().
* splitunc() no more returns illegal result for paths with redundant slashes.
* splitunc() now correctly processes the u'İ' character
(U+0130, LATIN CAPITAL LETTER I WITH DOT ABOVE).
* Added new tests for splitunc().
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r-- | Lib/ntpath.py | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 4f8f423..04f0b2d 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -136,6 +136,25 @@ def splitunc(p): using backslashes). unc+rest is always the input path. Paths containing drive letters never have an UNC part. """ + #if p[1:2] == ':': + #return '', p # Drive letter present + #firstTwo = p[0:2] + #if firstTwo == '//' or firstTwo == '\\\\': + ## is a UNC path: + ## vvvvvvvvvvvvvvvvvvvv equivalent to drive letter + ## \\machine\mountpoint\directories... + ## directory ^^^^^^^^^^^^^^^ + #normp = normcase(p) + #index = normp.find('\\', 2) + #if index == -1: + ###raise RuntimeError, 'illegal UNC path: "' + p + '"' + #return ("", p) + #index = normp.find('\\', index + 1) + #if index == -1: + #index = len(p) + #return p[:index], p[index:] + #return '', p + if p[1:2] == ':': return '', p # Drive letter present firstTwo = p[0:2] @@ -144,15 +163,18 @@ def splitunc(p): # vvvvvvvvvvvvvvvvvvvv equivalent to drive letter # \\machine\mountpoint\directories... # directory ^^^^^^^^^^^^^^^ - normp = normcase(p) - index = normp.find('\\', 2) - if index == -1: - ##raise RuntimeError, 'illegal UNC path: "' + p + '"' - return ("", p) - index = normp.find('\\', index + 1) - if index == -1: - index = len(p) - return p[:index], p[index:] + normp = p.replace('\\', '/') + index = normp.find('/', 2) + if index <= 2: + return '', p + index2 = normp.find('/', index + 1) + # a UNC path can't have two slashes in a row + # (after the initial two) + if index2 == index + 1: + return '', p + if index2 == -1: + index2 = len(p) + return p[:index2], p[index2:] return '', p |