From 3ee3a2486fe75ed858f8a3defe0fc79b2743d5df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Loiselet?= Date: Fri, 29 Jul 2022 21:33:23 +0200 Subject: [PATCH] build: trim trailing whitespace from dockerignore entries (#2733) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(dockerignore): trim trailing whitespace Signed-off-by: Clément Loiselet --- docker/utils/build.py | 3 +++ tests/integration/api_build_test.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/docker/utils/build.py b/docker/utils/build.py index ac060434d..59564c4cd 100644 --- a/docker/utils/build.py +++ b/docker/utils/build.py @@ -224,6 +224,9 @@ def __init__(self, pattern_str): @classmethod def normalize(cls, p): + # Remove trailing spaces + p = p.strip() + # Leading and trailing slashes are not relevant. Yes, # "foo.py/" must exclude the "foo.py" regular file. "." # components are not relevant either, even if the whole diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py index ef48e12ed..606c3b7e1 100644 --- a/tests/integration/api_build_test.py +++ b/tests/integration/api_build_test.py @@ -100,7 +100,9 @@ def test_build_with_dockerignore(self): 'ignored', 'Dockerfile', '.dockerignore', + ' ignored-with-spaces ', # check that spaces are trimmed '!ignored/subdir/excepted-file', + '! ignored/subdir/excepted-with-spaces ' '', # empty line, '#*', # comment line ])) @@ -111,6 +113,9 @@ def test_build_with_dockerignore(self): with open(os.path.join(base_dir, '#file.txt'), 'w') as f: f.write('this file should not be ignored') + with open(os.path.join(base_dir, 'ignored-with-spaces'), 'w') as f: + f.write("this file should be ignored") + subdir = os.path.join(base_dir, 'ignored', 'subdir') os.makedirs(subdir) with open(os.path.join(subdir, 'file'), 'w') as f: @@ -119,6 +124,9 @@ def test_build_with_dockerignore(self): with open(os.path.join(subdir, 'excepted-file'), 'w') as f: f.write("this file should not be ignored") + with open(os.path.join(subdir, 'excepted-with-spaces'), 'w') as f: + f.write("this file should not be ignored") + tag = 'docker-py-test-build-with-dockerignore' stream = self.client.build( path=base_dir, @@ -136,6 +144,7 @@ def test_build_with_dockerignore(self): assert sorted(list(filter(None, logs.split('\n')))) == sorted([ '/test/#file.txt', + '/test/ignored/subdir/excepted-with-spaces', '/test/ignored/subdir/excepted-file', '/test/not-ignored' ])