Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ trac/htdocs/js/messages/*.js
.project
.pydevproject
.settings
.DS_Store
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not related with this PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

5 changes: 4 additions & 1 deletion trac/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,10 @@ def normalize(path):
return os.path.normcase(os.path.abspath(path))
path = normalize(path)
parent = normalize(parent)
return path == parent or path.startswith(parent + os.sep)
try:
return os.path.commonpath((path, parent)) == parent
except ValueError:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why catching ValueError?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return False


class file_or_std(object):
Expand Down
11 changes: 11 additions & 0 deletions trac/util/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def test_is_path_below(self):
self.assertFalse(util.is_path_below('../sub/repos',
os.path.join(os.getcwd())))

def test_is_path_below_root_parent(self):
path = os.path.abspath(os.path.join(os.sep, 'tmp'))
self.assertTrue(util.is_path_below(path, os.sep))

if os.name == 'nt':
cwd = os.path.abspath(os.getcwd())
drive, _ = os.path.splitdrive(cwd)
drive_root = drive + os.sep
self.assertTrue(util.is_path_below(drive_root + 'tmp',
drive_root))

def test_native_path(self):
self.assertIsNone(util.native_path(None))
if os.name == 'posix':
Expand Down