diff --git a/src/Shared/FileMatcher.cs b/src/Shared/FileMatcher.cs index 1bfdc57490e..ebc622953da 100644 --- a/src/Shared/FileMatcher.cs +++ b/src/Shared/FileMatcher.cs @@ -131,7 +131,7 @@ internal FileMatcher(IFileSystem fileSystem, GetFileSystemEntries getFileSystemE "*", directory, false)); - IEnumerable filteredEntriesForPath = (pattern != null && pattern != "*" && pattern != "*.*") + IEnumerable filteredEntriesForPath = (pattern != null && !IsAllFilesWildcard(pattern)) ? allEntriesForPath.Where(o => IsMatch(Path.GetFileName(o), pattern)) : allEntriesForPath; return stripProjectDirectory @@ -886,7 +886,7 @@ struct RecursionState // The wildcard path portion of the excluded search matches the include search searchToExclude.RemainingWildcardDirectory == recursionState.RemainingWildcardDirectory && // The exclude search will match ALL filenames OR - (searchToExclude.SearchData.Filespec == "*" || searchToExclude.SearchData.Filespec == "*.*" || + (IsAllFilesWildcard(searchToExclude.SearchData.Filespec) || // The exclude search filename pattern matches the include search's pattern searchToExclude.SearchData.Filespec == recursionState.SearchData.Filespec)) { @@ -1091,7 +1091,11 @@ struct RecursionState private static bool MatchFileRecursionStep(RecursionState recursionState, string file) { - if (recursionState.SearchData.Filespec != null) + if (IsAllFilesWildcard(recursionState.SearchData.Filespec)) + { + return true; + } + else if (recursionState.SearchData.Filespec != null) { return IsMatch(Path.GetFileName(file), recursionState.SearchData.Filespec); } @@ -2564,6 +2568,17 @@ private static bool DirectoryEndsWithPattern(string directoryPath, string patter return (index != -1 && IsMatch(directoryPath.Substring(index + 1), pattern)); } + /// + /// Returns true if is * or *.*. + /// + /// The filename pattern to check. + private static bool IsAllFilesWildcard(string pattern) => pattern?.Length switch + { + 1 => pattern[0] == '*', + 3 => pattern[0] == '*' && pattern[1] == '.' && pattern[2] == '*', + _ => false + }; + internal static bool IsRecursiveDirectoryMatch(string path) => path.TrimTrailingSlashes() == recursiveDirectoryMatch; } }