diff options
author | Joffrey F <joffrey@docker.com> | 2017-08-15 14:54:53 -0700 |
---|---|---|
committer | Joffrey F <f.joffrey@gmail.com> | 2017-08-17 13:38:40 -0700 |
commit | 7f5739dc025af101e939b1403cf46a68fbc2dc97 (patch) | |
tree | 86cadac559241b77403fd3af2859d673b200bcf1 | |
parent | 7139e2d8f1ea82340417add02090bfaf7794f159 (diff) | |
download | docker-py-7f5739dc025af101e939b1403cf46a68fbc2dc97.tar.gz |
Leading slash in .dockerignore should be ignored
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | docker/utils/build.py | 1 | ||||
-rw-r--r-- | tests/unit/utils_test.py | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/docker/utils/build.py b/docker/utils/build.py index 79b7249..d4223e7 100644 --- a/docker/utils/build.py +++ b/docker/utils/build.py @@ -26,6 +26,7 @@ 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] diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 7045d23..4a391fa 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -768,6 +768,11 @@ class ExcludePathsTest(unittest.TestCase): self.all_paths - set(['foo/a.py']) ) + def test_single_subdir_single_filename_leading_slash(self): + assert self.exclude(['/foo/a.py']) == convert_paths( + self.all_paths - set(['foo/a.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']) |