summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Loiselet <claementi@gmail.com>2022-07-29 21:33:23 +0200
committerGitHub <noreply@github.com>2022-07-29 15:33:23 -0400
commit3ee3a2486fe75ed858f8a3defe0fc79b2743d5df (patch)
treed1faa893357aec45eba416ecd1cb344bfec4ee51
parent868e996269b6934420f0cd2104621b6f45f668e5 (diff)
downloaddocker-py-3ee3a2486fe75ed858f8a3defe0fc79b2743d5df.tar.gz
build: trim trailing whitespace from dockerignore entries (#2733)
fix(dockerignore): trim trailing whitespace Signed-off-by: Clément Loiselet <clement.loiselet@capgemini.com>
-rw-r--r--docker/utils/build.py3
-rw-r--r--tests/integration/api_build_test.py9
2 files changed, 12 insertions, 0 deletions
diff --git a/docker/utils/build.py b/docker/utils/build.py
index ac06043..59564c4 100644
--- a/docker/utils/build.py
+++ b/docker/utils/build.py
@@ -224,6 +224,9 @@ class Pattern:
@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 ef48e12..606c3b7 100644
--- a/tests/integration/api_build_test.py
+++ b/tests/integration/api_build_test.py
@@ -100,7 +100,9 @@ class BuildTest(BaseAPIIntegrationTest):
'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 @@ class BuildTest(BaseAPIIntegrationTest):
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 @@ class BuildTest(BaseAPIIntegrationTest):
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 @@ class BuildTest(BaseAPIIntegrationTest):
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'
])