Skip to content

Commit d00ed40

Browse files
committed
Need to escape regex pattern with external component. (#241)
* Need to escape regex pattern with external component. LanguageServer.CreateCompletionItem was causing a editor host crash because it (er *I*) was injecting tooltip text (returned by the PS engine) into a regex pattern without escaping it. One of the completion items was 'Notepad++.exe' which resulted in a regex parsing error. Would like to add a test for this at some point but need to think on it. CreateCompletionItem is private. Fixes #193 * Updated the comment to reflect the correct issue number in the PSES repo.
1 parent 916b5e4 commit d00ed40

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,13 +1128,16 @@ private static CompletionItem CreateCompletionItem(
11281128
// from the ToolTipText - if there is any ToolTipText.
11291129
if (completionDetails.ToolTipText != null)
11301130
{
1131+
// Fix for #240 - notepad++.exe in tooltip text caused regex parser to throw.
1132+
string escapedToolTipText = Regex.Escape(completionDetails.ToolTipText);
1133+
11311134
// Don't display ToolTipText if it is the same as the ListItemText.
11321135
// Reject command syntax ToolTipText - it's too much to display as a detailString.
11331136
if (!completionDetails.ListItemText.Equals(
11341137
completionDetails.ToolTipText,
11351138
StringComparison.OrdinalIgnoreCase) &&
11361139
!Regex.IsMatch(completionDetails.ToolTipText,
1137-
@"^\s*" + completionDetails.ListItemText + @"\s+\["))
1140+
@"^\s*" + escapedToolTipText + @"\s+\["))
11381141
{
11391142
detailString = completionDetails.ToolTipText;
11401143
}

0 commit comments

Comments
 (0)