mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
[3.11] gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls (GH-108248)
gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls (GH-108248)
---------
(cherry picked from commit de33b5c662
)
Co-authored-by: Steve Dower <steve.dower@python.org>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
parent
d22ac0c605
commit
8927cf0200
3 changed files with 22 additions and 0 deletions
|
@ -695,6 +695,14 @@ else:
|
|||
try:
|
||||
path = _getfinalpathname(path)
|
||||
initial_winerror = 0
|
||||
except ValueError as ex:
|
||||
# gh-106242: Raised for embedded null characters
|
||||
# In strict mode, we convert into an OSError.
|
||||
# Non-strict mode returns the path as-is, since we've already
|
||||
# made it absolute.
|
||||
if strict:
|
||||
raise OSError(str(ex)) from None
|
||||
path = normpath(path)
|
||||
except OSError as ex:
|
||||
if strict:
|
||||
raise
|
||||
|
@ -714,6 +722,10 @@ else:
|
|||
try:
|
||||
if _getfinalpathname(spath) == path:
|
||||
path = spath
|
||||
except ValueError as ex:
|
||||
# Unexpected, as an invalid path should not have gained a prefix
|
||||
# at any point, but we ignore this error just in case.
|
||||
pass
|
||||
except OSError as ex:
|
||||
# If the path does not exist and originally did not exist, then
|
||||
# strip the prefix anyway.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue