8000 Fix the issue Wildcard matching should be used in help file search · PowerShell/PowerShell@2f575b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f575b7

Browse files
committed
Fix the issue Wildcard matching should be used in help file search
1 parent 7a51b44 commit 2f575b7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/System.Management.Automation/help/MUIFileSearcher.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ private string[] GetFiles(string path, string pattern)
122122
ArrayList result = new ArrayList();
123123
string[] files = Directory.GetFiles(path);
124124

125-
string regexPattern = pattern.Replace(".", @"\.");
126-
regexPattern = regexPattern.Replace("*", ".*");
127-
regexPattern = regexPattern.Replace("?", ".?");
125+
var wildcardPattern = WildcardPattern.ContainsWildcardCharacters(pattern)
126+
? WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase)
127+
: null;
128128

129129
foreach (string filePath in files)
130130
{
@@ -133,11 +133,12 @@ private string[] GetFiles(string path, string pattern)
133133
result.Add(filePath);
134134
break;
135135
}
136-
// If the input is pattern instead of string, we need to use Regex expression.
137-
if (pattern.Contains("*") || pattern.Contains("?"))
138-
{
139-
if (Regex.IsMatch(filePath, regexPattern))
140-
{
136+
137+
if (wildcardPattern != null)
138+
{
139+
string fileName = Path.GetFileName(filePath);
140+
if (wildcardPattern.IsMatch(fileName))
141+
{
141142
result.Add(filePath);
142143
}
143144
}

0 commit comments

Comments
 (0)
0