gh-102475: Fix os.path.realpath() for names which look like a drive by serhiy-storchaka · Pull Request #155399 · python/cpython · GitHub
Skip to content

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

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:gh-102475-realpath-join
Aug 29, 2026
Merged

serhiy-storchaka merged 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
@serhiy-storchaka
serhiy-storchaka merged commit 0c38e05 into python:main Aug 29, 2026
58 checks passed
@serhiy-storchaka
serhiy-storchaka deleted the gh-102475-realpath-join branch August 29, 2026 18:17
@miss-islington-app

Copy link
Copy Markdown

@bedevere-app

bedevere-app Bot commented Aug 29, 2026

Copy link
Copy Markdown

GH-156593 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 29, 2026
@bedevere-app

bedevere-app Bot commented Aug 29, 2026

Copy link
Copy Markdown

GH-156594 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Aug 29, 2026
@bedevere-app

bedevere-app Bot commented Aug 29, 2026

Copy link
Copy Markdown

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Aug 29, 2026
serhiy-storchaka added a commit that referenced this pull request Aug 29, 2026
…drive (GH-155399) (GH-156595)

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.
(cherry picked from commit 0c38e05)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this pull request Aug 29, 2026
…drive (GH-155399) (GH-156594)

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.
(cherry picked from commit 0c38e05)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
…rive (pythonGH-155399)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant