mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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 * Update 2023-08-22-00-36-57.gh-issue-106242.q24ITw.rst mention Windows and the former incorrect ValueError. --------- Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
parent
531930f47f
commit
de33b5c662
3 changed files with 22 additions and 0 deletions
|
@ -721,6 +721,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
|
||||
|
@ -740,6 +748,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