moby/pkg/fileutils
Aaron Lehmann 90f8d1b675 fileutils: Fix incorrect handling of "**/foo" pattern
(*PatternMatcher).Matches includes a special case for when the pattern
matches a parent dir, even though it doesn't match the current path.
However, it assumes that the parent dir which would match the pattern
must have the same number of separators as the pattern itself. This
doesn't hold true with a patern like "**/foo". A file foo/bar would have
len(parentPathDirs) == 1, which is less than the number of path
len(pattern.dirs) == 2... therefore this check would be skipped.

Given that "**/foo" matches "foo", I think it's a bug that the "parent
subdir matches" check is being skipped in this case.

It seems safer to loop over the parent subdirs and check each against
the pattern. It's possible there is a safe optimization to check only a
certain subset, but the existing logic seems unsafe.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
2021-07-26 11:28:10 -07:00
..
fileutils.go fileutils: Fix incorrect handling of "**/foo" pattern 2021-07-26 11:28:10 -07:00
fileutils_darwin.go Add canonical import comment 2018-02-05 16:51:57 -05:00
fileutils_test.go fileutils: Fix incorrect handling of "**/foo" pattern 2021-07-26 11:28:10 -07:00
fileutils_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
fileutils_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00