Repository navigation
Handle leading // for posixpath.realpath #117338
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Mar 28, 2024 os.path.realpath()resolves the path using the current OS's rules, which might be more specific than POSIX. Both my Linux and macOS machines resolve//footo/foo. Are there any supported Python platforms where//isn't resolved to/?I'm currently on my Windows laptop, so I can't check.
In any case, the old implementation can never return//foobecausepathis set toos.sep.
Is there a "needs investigation" label?There doesn't seem to be anything like a "needs investigation" label.
Happy to leave this issue open for a bit while you further research a repro case, but if we can't find one, then I think this issue should be closed as "can't repro".
Also, the current behaviour is undocumented:
Join two paths, normalizing and eliminating any symbolic links encountered in the second path.
Normalizing doesn't touch the double slash &
//is not a symlink.You're quoting a comment above the internal
_joinrealpath()function.Both the
posixpath.realpath()docstring, and the online docs, describe it as returning a canonical path. The online docs add:This function emulates the operating system’s procedure for making a path canonical
OK, but that comment doesn't document this feature, which it probably should, in case this works correctly.
Why do you want to fix this, and could you describe in more detail how the changes relate to the specification you are pointing to? I don't see what in the specification requires this.
- changed the title
[-]Handle leading `//` for `realpath.commonpath`[/-][+]Handle leading `//` for `posixpath.realpath`[/+]on Mar 29, 2024 We don't need to document every detail of what
realpath()does. Tests would be welcome, thoughReacted by Erlend E. AaslandI've added just one sentence in this pull request: #117350.
Join two paths, normalizing and eliminating any symbolic links encountered in the second path. Two leading slashes are replaced by a single slash.
Where should I add the test though? It doesn't really fit in with the rest of the changes.


Bug report
Bug description:
Expected:
//foowith precisely two leading slashes, see: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13This can be quite easily solved using
posixpath.splitroot, see the PR.CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
//forposixpath.realpath#117340