Skip to content

Commit 3ee3a24

Browse files
authored
build: trim trailing whitespace from dockerignore entries (#2733)
fix(dockerignore): trim trailing whitespace Signed-off-by: Clément Loiselet <[email protected]>
1 parent 868e996 commit 3ee3a24

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

docker/utils/build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ def __init__(self, pattern_str):
224224
@classmethod
225225
def normalize(cls, p):
226226

227+
# Remove trailing spaces
228+
p = p.strip()
229+
227230
# Leading and trailing slashes are not relevant. Yes,
228231
# "foo.py/" must exclude the "foo.py" regular file. "."
229232
# components are not relevant either, even if the whole

tests/integration/api_build_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ def test_build_with_dockerignore(self):
100100
'ignored',
101101
'Dockerfile',
102102
'.dockerignore',
103+
' ignored-with-spaces ', # check that spaces are trimmed
103104
'!ignored/subdir/excepted-file',
105+
'! ignored/subdir/excepted-with-spaces '
104106
'', # empty line,
105107
'#*', # comment line
106108
]))
@@ -111,6 +113,9 @@ def test_build_with_dockerignore(self):
111113
with open(os.path.join(base_dir, '#file.txt'), 'w') as f:
112114
f.write('this file should not be ignored')
113115

116+
with open(os.path.join(base_dir, 'ignored-with-spaces'), 'w') as f:
117+
f.write("this file should be ignored")
118+
114119
subdir = os.path.join(base_dir, 'ignored', 'subdir')
115120
os.makedirs(subdir)
116121
with open(os.path.join(subdir, 'file'), 'w') as f:
@@ -119,6 +124,9 @@ def test_build_with_dockerignore(self):
119124
with open(os.path.join(subdir, 'excepted-file'), 'w') as f:
120125
f.write("this file should not be ignored")
121126

127+
with open(os.path.join(subdir, 'excepted-with-spaces'), 'w') as f:
128+
f.write("this file should not be ignored")
129+
122130
tag = 'docker-py-test-build-with-dockerignore'
123131
stream = self.client.build(
124132
path=base_dir,
@@ -136,6 +144,7 @@ def test_build_with_dockerignore(self):
136144

137145
assert sorted(list(filter(None, logs.split('\n')))) == sorted([
138146
'/test/#file.txt',
147+
'/test/ignored/subdir/excepted-with-spaces',
139148
'/test/ignored/subdir/excepted-file',
140149
'/test/not-ignored'
141150
])

0 commit comments

Comments
 (0)