Use wildcard matching in help file search (#3971)

This commit is contained in:
Chunqing Chen 2017-06-13 05:48:30 +08:00 committed by Jason Shirk
parent bebf487d10
commit b4b4e60670

View File

@ -122,9 +122,9 @@ namespace System.Management.Automation
ArrayList result = new ArrayList();
string[] files = Directory.GetFiles(path);
string regexPattern = pattern.Replace(".", @"\.");
regexPattern = regexPattern.Replace("*", ".*");
regexPattern = regexPattern.Replace("?", ".?");
var wildcardPattern = WildcardPattern.ContainsWildcardCharacters(pattern)
? WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase)
: null;
foreach (string filePath in files)
{
@ -133,10 +133,11 @@ namespace System.Management.Automation
result.Add(filePath);
break;
}
// If the input is pattern instead of string, we need to use Regex expression.
if (pattern.Contains("*") || pattern.Contains("?"))
if (wildcardPattern != null)
{
if (Regex.IsMatch(filePath, regexPattern))
string fileName = Path.GetFileName(filePath);
if (wildcardPattern.IsMatch(fileName))
{
result.Add(filePath);
}