diff --git a/owners.py b/owners.py index 8c503f12c..f46fef284 100644 --- a/owners.py +++ b/owners.py @@ -441,7 +441,7 @@ class Database(object): else: assert start.startswith(self.root) start = self.os_path.dirname(self.os_path.relpath(start, self.root)) - include_path = self.os_path.join(start, path) + include_path = self.os_path.normpath(self.os_path.join(start, path)) if include_path in self.override_files: return include_path diff --git a/testing_support/filesystem_mock.py b/testing_support/filesystem_mock.py index 7a0616abd..36a258e2d 100644 --- a/testing_support/filesystem_mock.py +++ b/testing_support/filesystem_mock.py @@ -77,6 +77,19 @@ class MockFileSystem(object): def open_for_reading(self, path): return StringIO.StringIO(self.read_binary_file(path)) + def normpath(self, path): + # This is not a complete implementation of normpath. Only covers what we + # use in tests. + result = [] + for part in path.split(self.sep): + if part == '..': + result.pop() + elif part == '.': + continue + else: + result.append(part) + return self.sep.join(result) + def read_binary_file(self, path): # Intentionally raises KeyError if we don't recognize the path. if self.files[path] is None: diff --git a/tests/owners_unittest.py b/tests/owners_unittest.py index 6aff93989..b8c008639 100755 --- a/tests/owners_unittest.py +++ b/tests/owners_unittest.py @@ -52,6 +52,7 @@ def test_repo(): '/chrome/renderer/OWNERS': owners_file(peter), '/chrome/renderer/gpu/gpu_channel_host.h': '', '/chrome/renderer/safe_browsing/scorer.h': '', + '/chrome/tools/OWNERS': owners_file(file='../OWNERS'), '/content/OWNERS': owners_file(john, darin, comment='foo', noparent=True), '/content/comment/OWNERS': owners_file(john + ' # for comments', darin + ' # for everything else'), @@ -415,6 +416,10 @@ class ReviewersForTest(_BaseTestCase): [[john], [darin]]) + def test_reviewers_for__relative_owners_file(self): + self.assert_reviewers_for(['chrome/tools/OWNERS'], + [[ben], [brett]]) + def test_reviewers_for__valid_inputs(self): db = self.db()