From c8f5a5ad4040560ce62d53002ecec12485b531f7 Mon Sep 17 00:00:00 2001 From: mefyl Date: Fri, 16 Feb 2018 11:22:29 +0100 Subject: Fix dockerignore handling of absolute path exceptions. Signed-off-by: mefyl --- docker/utils/build.py | 6 +++--- tests/unit/utils_test.py | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docker/utils/build.py b/docker/utils/build.py index d4223e7..e86a04e 100644 --- a/docker/utils/build.py +++ b/docker/utils/build.py @@ -26,13 +26,13 @@ def exclude_paths(root, patterns, dockerfile=None): if dockerfile is None: dockerfile = 'Dockerfile' - patterns = [p.lstrip('/') for p in patterns] exceptions = [p for p in patterns if p.startswith('!')] - include_patterns = [p[1:] for p in exceptions] + include_patterns = [p[1:].lstrip('/') for p in exceptions] include_patterns += [dockerfile, '.dockerignore'] - exclude_patterns = list(set(patterns) - set(exceptions)) + exclude_patterns = [ + p.lstrip('/') for p in list(set(patterns) - set(exceptions))] paths = get_paths(root, exclude_patterns, include_patterns, has_exceptions=len(exceptions) > 0) diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index eedcf71..0ee041a 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -758,6 +758,13 @@ class ExcludePathsTest(unittest.TestCase): self.all_paths - set(['foo/a.py']) ) + def test_exclude_include_absolute_path(self): + base = make_tree([], ['a.py', 'b.py']) + assert exclude_paths( + base, + ['/*', '!/*.py'] + ) == set(['a.py', 'b.py']) + def test_single_subdir_with_path_traversal(self): assert self.exclude(['foo/whoops/../a.py']) == convert_paths( self.all_paths - set(['foo/a.py']) -- cgit v1.2.1