Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
06be2c7f
Commit
06be2c7f
authored
Aug 21, 2019
by
Steve Dower
Committed by
GitHub
Aug 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-9949: Call normpath() in realpath() and avoid unnecessary prefixes (GH-15369)
parent
7ebdda0d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
5 deletions
+10
-5
Lib/ntpath.py
Lib/ntpath.py
+8
-3
Lib/test/test_ntpath.py
Lib/test/test_ntpath.py
+2
-2
No files found.
Lib/ntpath.py
View file @
06be2c7f
...
...
@@ -458,7 +458,8 @@ def normpath(path):
# in the case of paths with these prefixes:
# \\.\ -> device names
# \\?\ -> literal paths
# do not do any normalization, but return the path unchanged
# do not do any normalization, but return the path
# unchanged apart from the call to os.fspath()
return
path
path
=
path
.
replace
(
altsep
,
sep
)
prefix
,
path
=
splitdrive
(
path
)
...
...
@@ -575,7 +576,7 @@ else:
return
abspath
(
tail
)
def
realpath
(
path
):
path
=
os
.
fs
path
(
path
)
path
=
norm
path
(
path
)
if
isinstance
(
path
,
bytes
):
prefix
=
b'
\
\
\
\
?
\
\
'
unc_prefix
=
b'
\
\
\
\
?
\
\
UNC
\
\
'
...
...
@@ -586,6 +587,7 @@ else:
unc_prefix
=
'
\
\
\
\
?
\
\
UNC
\
\
'
new_unc_prefix
=
'
\
\
\
\
'
cwd
=
os
.
getcwd
()
did_not_exist
=
not
exists
(
path
)
had_prefix
=
path
.
startswith
(
prefix
)
path
=
_getfinalpathname_nonstrict
(
path
)
# The path returned by _getfinalpathname will always start with \\?\ -
...
...
@@ -603,7 +605,10 @@ else:
if
_getfinalpathname
(
spath
)
==
path
:
path
=
spath
except
OSError
as
ex
:
pass
# If the path does not exist and originally did not exist, then
# strip the prefix anyway.
if
ex
.
winerror
in
{
2
,
3
}
and
did_not_exist
:
path
=
spath
return
path
...
...
Lib/test/test_ntpath.py
View file @
06be2c7f
...
...
@@ -333,11 +333,11 @@ class TestNtpath(unittest.TestCase):
self.assertEqual(ntpath.realpath(ABSTFN + "1
\
\
.."),
ntpath.dirname(ABSTFN))
self.assertEqual(ntpath.realpath(ABSTFN + "1
\
\
..
\
\
x"),
ntpath.dirname(
P +
ABSTFN) + "
\
\
x")
ntpath.dirname(ABSTFN) + "
\
\
x")
os.symlink(ABSTFN + "x", ABSTFN + "y")
self.assertEqual(ntpath.realpath(ABSTFN + "1
\
\
..
\
\
"
+ ntpath.basename(ABSTFN) + "y"),
P +
ABSTFN + "x")
ABSTFN + "x")
self.assertIn(ntpath.realpath(ABSTFN + "1
\
\
..
\
\
"
+ ntpath.basename(ABSTFN) + "1"),
expected)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment