Skip to content

gh-102475: Fix os.path.realpath() for names which look like a drive - #155399

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-102475-realpath-join
Open

gh-102475: Fix os.path.realpath() for names which look like a drive#155399
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-102475-realpath-join

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

The documentation says that in the non-strict mode the unresolved part of the path is appended, but it was joined with join(), which resets the path if the tail looks like a drive:

>>> ntpath.realpath('C:/spam/a:b')
'a:b'

It is now simply appended, using the naive join suggested by @eryksun.

realpath() also used join(cwd, path) for a relative path, which left a path relative to another drive unresolved. It now uses abspath(), so such path is resolved against the root directory of that drive, as GetFullPathNameW() does:

>>> ntpath.realpath('Z:spam')   # Z: does not exist
'Z:spam'                        # now 'Z:\\spam'

…rive

The unresolved part of the path was joined with the resolved part using
join(), so a component containing a colon (e.g. "spam:eggs") reset the path.
It is now simply appended.

A path relative to a drive which does not exist (e.g. "Z:spam") is now
resolved against the root directory of that drive, as the Windows path
normalization does.
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant