Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def get_paths(root, exclude_patterns, include_patterns, has_exceptions=False):

def match_path(path, pattern):
pattern = pattern.rstrip('/')
if pattern:
pattern = os.path.relpath(pattern)

pattern_components = pattern.split('/')
path_components = path.split('/')[:len(pattern_components)]
return fnmatch('/'.join(path_components), pattern)
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,9 @@ def test_exclude_dockerfile_child(self):
def test_single_filename(self):
assert self.exclude(['a.py']) == self.all_paths - set(['a.py'])

def test_single_filename_leading_dot_slash(self):
assert self.exclude(['./a.py']) == self.all_paths - set(['a.py'])

# As odd as it sounds, a filename pattern with a trailing slash on the
# end *will* result in that file being excluded.
def test_single_filename_trailing_slash(self):
Expand Down Expand Up @@ -831,6 +834,11 @@ def test_question_mark(self):
def test_single_subdir_single_filename(self):
assert self.exclude(['foo/a.py']) == self.all_paths - set(['foo/a.py'])

def test_single_subdir_with_path_traversal(self):
assert self.exclude(['foo/whoops/../a.py']) == self.all_paths - set([
'foo/a.py',
])

def test_single_subdir_wildcard_filename(self):
assert self.exclude(['foo/*.py']) == self.all_paths - set([
'foo/a.py', 'foo/b.py',
Expand Down