From 3df0653493d5f2ff5e17de8211a32aed8f4c1965 Mon Sep 17 00:00:00 2001 From: Veli-Matti Lintu Date: Fri, 18 Aug 2017 11:48:09 +0300 Subject: [PATCH] Commit d798afca made changes for the handling of '**' patterns in .dockerignore. This causes an IndexError with patterns ending with '**', e.g. 'subdir/**'. This adds a missing boundary check before checking for trailing '/'. Signed-off-by: Veli-Matti Lintu --- docker/utils/fnmatch.py | 2 +- tests/unit/utils_test.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docker/utils/fnmatch.py b/docker/utils/fnmatch.py index e51bd815..42461dd7 100644 --- a/docker/utils/fnmatch.py +++ b/docker/utils/fnmatch.py @@ -75,7 +75,7 @@ def translate(pat): # is some flavor of "**" i = i + 1 # Treat **/ as ** so eat the "/" - if pat[i] == '/': + if i < n and pat[i] == '/': i = i + 1 if i >= n: # is "**EOF" - to align with .gitignore just accept all diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 4a391fac..2fa1d051 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -874,6 +874,23 @@ class ExcludePathsTest(unittest.TestCase): ) ) + def test_trailing_double_wildcard(self): + assert self.exclude(['subdir/**']) == convert_paths( + self.all_paths - set( + ['subdir/file.txt', + 'subdir/target/file.txt', + 'subdir/target/subdir/file.txt', + 'subdir/subdir2/file.txt', + 'subdir/subdir2/target/file.txt', + 'subdir/subdir2/target/subdir/file.txt', + 'subdir/target', + 'subdir/target/subdir', + 'subdir/subdir2', + 'subdir/subdir2/target', + 'subdir/subdir2/target/subdir'] + ) + ) + class TarTest(unittest.TestCase): def test_tar_with_excludes(self):