Bug 1612115 - [mozlint] Fix an error in the path filtering logic, r=linter-reviewers,sylvestre CLOSED TREE

Essentially:

  FilterPath("docs").contains("docshell")

was returning True because "docshell" startswith "docs".

Differential Revision: https://phabricator.services.mozilla.com/D64661

--HG--
extra : source : 10f69335c6f5779522b16c3376fc78147e4a3ce0
extra : histedit_source : 7577a814e2cdf6168cd88460c42e4472dfb8f734
This commit is contained in:
Andrew Halberstadt 2020-02-27 21:52:50 +00:00
parent a1bab87650
commit 8f84b09e44
2 changed files with 16 additions and 3 deletions

View File

@ -57,9 +57,16 @@ class FilterPath(object):
a = os.path.abspath(self.path)
b = os.path.normpath(os.path.abspath(other))
if b.startswith(a):
return True
return False
parts_a = a.split(os.sep)
parts_b = b.split(os.sep)
if len(parts_a) > len(parts_b):
return False
for i, part in enumerate(parts_a):
if part != parts_b[i]:
return False
return True
def __repr__(self):
return repr(self.path)

View File

@ -65,6 +65,12 @@ TEST_CASES = (
'expected': ['subdir1'],
'expected_exclude': ['subdir1/subdir3'],
},
{
'paths': ['docshell'],
'include': ['docs'],
'exclude': [],
'expected': [],
}
)