Skip to content

Commit 61006aa

Browse files
committed
Refine online help feature
This change gives a namespace to the 'showonlinehelp' message type, making it 'powerShell/showOnlineHelp'. Also changes the request parameter type to a string and uses PSCommand.AddCommand, etc to avoid script injection attacks.
1 parent ac82a4b commit 61006aa

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/PowerShellEditorServices.Host/LanguageServer.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,19 @@ protected Task HandleShutdownRequest(
135135
}
136136

137137
protected async Task HandleShowOnlineHelpRequest(
138-
object helpParams,
138+
string helpParams,
139139
EditorSession editorSession,
140140
RequestContext<object, object> requestContext)
141141
{
142-
var psCommand = new PSCommand();
143-
144142
if (helpParams == null) { helpParams = "get-help"; }
145143

146-
var script = string.Format("get-help {0} -Online", helpParams);
147-
148-
psCommand.AddScript(script);
144+
var psCommand = new PSCommand();
145+
psCommand.AddCommand("Get-Help");
146+
psCommand.AddArgument(helpParams);
147+
psCommand.AddParameter("Online");
149148

150-
var result = await editorSession.PowerShellContext.ExecuteCommand<object>(
151-
psCommand);
149+
await editorSession.PowerShellContext.ExecuteCommand<object>(
150+
psCommand);
152151

153152
await requestContext.SendResult(null);
154153
}

src/PowerShellEditorServices.Protocol/LanguageServer/ShowOnlineHelpRequest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer
99
{
1010
public class ShowOnlineHelpRequest
1111
{
12-
public static readonly RequestType<object, object, object> Type = RequestType<object, object, object>.Create("showonlinehelp");
12+
public static readonly
13+
RequestType<string, object, object> Type =
14+
RequestType<string, object, object>.Create("powerShell/showOnlineHelp");
1315
}
1416
}

0 commit comments

Comments
 (0)