Util: fix is_path_below() when parent is root path#28
Open
Ahelsamahy wants to merge 1 commit intoedgewall:trunkfrom
Open
Util: fix is_path_below() when parent is root path#28Ahelsamahy wants to merge 1 commit intoedgewall:trunkfrom
Ahelsamahy wants to merge 1 commit intoedgewall:trunkfrom
Conversation
Author
|
I did open a ticket on the website related to the current PR on https://trac.edgewall.org/ticket/13896 |
jun66j5
reviewed
Apr 11, 2026
| return path == parent or path.startswith(parent + os.sep) | ||
| try: | ||
| return os.path.commonpath((path, parent)) == parent | ||
| except ValueError: |
Author
There was a problem hiding this comment.
It is the return error from commonpath https://docs.python.org/3.10/library/os.path.html#os.path.commonpath
jun66j5
reviewed
Apr 11, 2026
| .project | ||
| .pydevproject | ||
| .settings | ||
| .DS_Store |
Member
There was a problem hiding this comment.
It is not related with this PR.
Author
There was a problem hiding this comment.
Agree, I did add it for my side as I'm using macOS and this is how it keeps trace of the dir layout. Should I remove it? My system will auto generate it again when i open finder on this repo locally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes an edge case in
trac.util.is_path_below()when the parent path is a filesystem root.Problem
The previous implementation used string prefix matching:
path == parent or path.startswith(parent + os.sep)This fails for root parents (for example
/on POSIX, and drive roots on Windows), because appendingos.septo a root path does not produce a reliable boundary check.Solution
Replaced the prefix check with
os.path.commonpath(...).Tests
Added a regression test in
PathTestCase: