-
Notifications
You must be signed in to change notification settings - Fork 541
fix: Use Start-Process for online help to avoid security warning #5447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,14 +2,9 @@ | |
| // Licensed under the MIT License. | ||
|
|
||
| import vscode = require("vscode"); | ||
| import { NotificationType } from "vscode-languageclient"; | ||
| import type { LanguageClient } from "vscode-languageclient/node"; | ||
| import { LanguageClientConsumer } from "../languageClientConsumer"; | ||
|
|
||
| interface IShowHelpNotificationArguments {} | ||
|
|
||
| export const ShowHelpNotificationType = | ||
| new NotificationType<IShowHelpNotificationArguments>("powerShell/showHelp"); | ||
| import { PowerShellIntegratedConsole } from "../powerShellIntegratedConsole"; | ||
|
|
||
| export class ShowHelpFeature extends LanguageClientConsumer { | ||
| private command: vscode.Disposable; | ||
|
|
@@ -19,29 +14,38 @@ export class ShowHelpFeature extends LanguageClientConsumer { | |
| this.command = vscode.commands.registerCommand( | ||
| "PowerShell.ShowHelp", | ||
| async (item?) => { | ||
| if (!item?.Name) { | ||
| let text: string | undefined; | ||
| if (item?.Name) { | ||
| text = item.Name; | ||
| } else { | ||
| const editor = vscode.window.activeTextEditor; | ||
| if (editor === undefined) { | ||
| return; | ||
| } | ||
|
|
||
| const selection = editor.selection; | ||
| const doc = editor.document; | ||
| const cwr = doc.getWordRangeAtPosition(selection.active); | ||
| const text = doc.getText(cwr); | ||
| text = doc.getText(cwr); | ||
| } | ||
|
Comment on lines
25
to
+29
|
||
|
|
||
| const client = | ||
| await LanguageClientConsumer.getLanguageClient(); | ||
| await client.sendNotification(ShowHelpNotificationType, { | ||
| text, | ||
| }); | ||
| } else { | ||
| const client = | ||
| await LanguageClientConsumer.getLanguageClient(); | ||
| await client.sendNotification(ShowHelpNotificationType, { | ||
| text: item.Name, | ||
| }); | ||
| if (!text) { | ||
| return; | ||
| } | ||
|
|
||
| // We need to escape single quotes for the PowerShell command. | ||
| const escapedText = text.replace(/'/g, "''"); | ||
| const psCommand = | ||
|
Comment on lines
+35
to
+37
|
||
| `try { ` + | ||
| `$help = (Get-Help '${escapedText}' -ErrorAction Stop)[0]; ` + | ||
| `$uri = $help.RelatedLinks.NavigationLink[0].Uri; ` + | ||
| `if ($null -ne $uri) { Start-Process $uri } ` + | ||
| `} catch { ` + | ||
| `# This fails silently, which is similar to the old behavior where no browser ` + | ||
| `# would be opened if help is not found. ` + | ||
| `}`; | ||
|
|
||
| // We don't want to focus the terminal, and we don't want this to show up in history. | ||
| await PowerShellIntegratedConsole.instance.executeCommand(psCommand, false, false); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new import "../powerShellIntegratedConsole" (and
PowerShellIntegratedConsole.instance.executeCommand(...)) does not resolve anywhere insrc/—there is nopowerShellIntegratedConsole.tsand no exportedPowerShellIntegratedConsoleclass. This will fail TypeScript compilation. Either add/commit the missing module, or rework this to use the existing session/terminal plumbing (e.g., via the session manager /PowerShellProcessterminal) that already exists in this repo.