Skip to content

Commit 76f9c4c

Browse files
msftrncsdaxian-dbw
authored andcommitted
Prevent 'ArgumentOutOfRangeException' when showing the tab completion menu (#984)
- Prevent adjustment of `userCompletionText` in `FindUserCompletionTextPosition` when the match contains `{` in CompletionText[1] if the `userCompletionText` is not longer than 1 char - Preserve the splat sigil at start of completions of type `Variable`. Adjusting `userCompletionText` blindly led to `ArgumentOutOfRangeException` on incorrectly braced splats on input `@?`. Loss of the sigil of splats led to the splat sigil always being marked as replaced, and in situations where the PowerShell completion logic returned incorrect completions of splats with braces, led to a `ArgumentOutOfRangeException`.
1 parent 820f160 commit 76f9c4c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

PSReadLine/Completion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static string GetUnquotedText(CompletionResult match, bool consistentQuo
106106
{
107107
if (IsQuotedVariable(s))
108108
{
109-
return '$' + s.Substring(2, s.Length - 3);
109+
return s[0] + s.Substring(2, s.Length - 3);
110110
}
111111
return s;
112112
}
@@ -731,7 +731,7 @@ private Collection<CompletionResult> FilterCompletions(CommandCompletion complet
731731

732732
private int FindUserCompletionTextPosition(CompletionResult match, string userCompletionText)
733733
{
734-
return match.ResultType == CompletionResultType.Variable && match.CompletionText[1] == '{'
734+
return match.ResultType == CompletionResultType.Variable && userCompletionText.Length > 1 && match.CompletionText[1] == '{'
735735
? match.CompletionText.IndexOf(userCompletionText.Substring(1), StringComparison.OrdinalIgnoreCase) - 1
736736
: match.CompletionText.IndexOf(userCompletionText, StringComparison.OrdinalIgnoreCase);
737737
}

0 commit comments

Comments
 (0)