# HG changeset patch # User Andrew Halberstadt # Date 1539784341 0 # Wed Oct 17 13:52:21 2018 +0000 # Node ID fbd19192e4fc1e66c4eefaede7d356fdd8627285 # Parent c77616575b61861ab271efcb0a821ad2c8085687 Bug 1494069 - [mozlint] Fix edge case in pathutils.collapse, r=rwood I missed an edge case where the computed base itself was specified in the paths input. Differential Revision: https://phabricator.services.mozilla.com/D8842 diff --git a/python/mozlint/mozlint/pathutils.py b/python/mozlint/mozlint/pathutils.py --- a/python/mozlint/mozlint/pathutils.py +++ b/python/mozlint/mozlint/pathutils.py @@ -95,16 +95,19 @@ def collapse(paths, base=None, dotfiles= if not base: paths = map(mozpath.abspath, paths) base = mozpath.commonprefix(paths) if not os.path.isdir(base): base = os.path.dirname(base) + if base in paths: + return [base] + covered = set() full = set() for name in os.listdir(base): if not dotfiles and name[0] == '.': continue path = mozpath.join(base, name) full.add(path) diff --git a/python/mozlint/test/test_pathutils.py b/python/mozlint/test/test_pathutils.py --- a/python/mozlint/test/test_pathutils.py +++ b/python/mozlint/test/test_pathutils.py @@ -105,16 +105,17 @@ def test_filterpaths(filterpaths, test): @pytest.mark.parametrize('paths,expected', [ (['subdir1/*'], ['subdir1']), (['subdir2/*'], ['subdir2']), (['subdir1/*.*', 'subdir1/subdir3/*', 'subdir2/*'], ['subdir1', 'subdir2']), ([root + '/*', 'subdir1/*.*', 'subdir1/subdir3/*', 'subdir2/*'], [root]), (['subdir1/b.py', 'subdir1/subdir3'], ['subdir1/b.py', 'subdir1/subdir3']), (['subdir1/b.py', 'subdir1/b.js'], ['subdir1/b.py', 'subdir1/b.js']), + (['subdir1/subdir3'], ['subdir1/subdir3']), ]) def test_collapse(paths, expected): inputs = [] for path in paths: base, name = os.path.split(path) if '*' in name: for n in os.listdir(base): if not fnmatch(n, name):