diff --git a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs index 409cb902f7..7c700317e8 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs @@ -691,8 +691,9 @@ namespace System.Management.Automation /// private static class PSv2CompletionCompleter { + private const string CharsRequiringQuotedString = "`&@'#{}()$,;|<> \t"; + private static readonly Regex s_cmdletTabRegex = new Regex(@"^[\w\*\?]+-[\w\*\?]*"); - private static readonly char[] s_charsRequiringQuotedString = "`&@'#{}()$,;|<> \t".ToCharArray(); #region "Handle Command" @@ -939,7 +940,7 @@ namespace System.Management.Automation private static string AddQuoteIfNecessary(string completionText, string quote, bool completingAtStartOfLine) { - if (completionText.IndexOfAny(s_charsRequiringQuotedString) != -1) + if (completionText.AsSpan().IndexOfAny(CharsRequiringQuotedString) >= 0) { bool needAmpersand = quote.Length == 0 && completingAtStartOfLine; string quoteInUse = quote.Length == 0 ? "'" : quote;