Skip to content

Commit

Permalink
Support any OSC link scheme
Browse files Browse the repository at this point in the history
Fixes #176812
  • Loading branch information
Tyriar committed Apr 2, 2024
1 parent 32d5ad5 commit eca9ac7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const enum TerminalSettingId {
WindowsEnableConpty = 'terminal.integrated.windowsEnableConpty',
WordSeparators = 'terminal.integrated.wordSeparators',
EnableFileLinks = 'terminal.integrated.enableFileLinks',
AllowedLinkSchemes = 'terminal.integrated.allowedLinkSchemes',
UnicodeVersion = 'terminal.integrated.unicodeVersion',
LocalEchoLatencyThreshold = 'terminal.integrated.localEchoLatencyThreshold',
LocalEchoEnabled = 'terminal.integrated.localEchoEnabled',
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export interface ITerminalConfiguration {
windowsEnableConpty: boolean;
wordSeparators: string;
enableFileLinks: 'off' | 'on' | 'notRemote';
allowedLinkSchemes: string[];
unicodeVersion: '6' | '11';
localEchoLatencyThreshold: number;
localEchoExcludePrograms: ReadonlyArray<string>;
Expand Down
15 changes: 15 additions & 0 deletions src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,21 @@ const terminalConfiguration: IConfigurationNode = {
],
default: 'on'
},
[TerminalSettingId.AllowedLinkSchemes]: {
description: localize('terminal.integrated.allowedLinkSchemes', "An array of strings containing the URI schemes that the terminal is allowed to open links for. By default, only a small subset of possible schemes are allowed for security reasons."),
type: 'array',
items: {
type: 'string'
},
default: [
'file',
'http',
'https',
'mailto',
'vscode',
'vscode-insiders',
]
},
[TerminalSettingId.UnicodeVersion]: {
type: 'string',
enum: ['6', '11'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { TerminalLocalFileLinkOpener, TerminalLocalFolderInWorkspaceLinkOpener,
import { TerminalLocalLinkDetector } from 'vs/workbench/contrib/terminalContrib/links/browser/terminalLocalLinkDetector';
import { TerminalUriLinkDetector } from 'vs/workbench/contrib/terminalContrib/links/browser/terminalUriLinkDetector';
import { TerminalWordLinkDetector } from 'vs/workbench/contrib/terminalContrib/links/browser/terminalWordLinkDetector';
import { ITerminalExternalLinkProvider, TerminalLinkQuickPickEvent } from 'vs/workbench/contrib/terminal/browser/terminal';
import { ITerminalConfigurationService, ITerminalExternalLinkProvider, TerminalLinkQuickPickEvent } from 'vs/workbench/contrib/terminal/browser/terminal';
import { ILinkHoverTargetOptions, TerminalHover } from 'vs/workbench/contrib/terminal/browser/widgets/terminalHoverWidget';
import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/widgets/widgetManager';
import { IXtermCore } from 'vs/workbench/contrib/terminal/browser/xterm-private';
Expand Down Expand Up @@ -53,6 +53,7 @@ export class TerminalLinkManager extends DisposableStore {
capabilities: ITerminalCapabilityStore,
private readonly _linkResolver: ITerminalLinkResolver,
@IConfigurationService private readonly _configurationService: IConfigurationService,
@ITerminalConfigurationService private readonly _termninalConfigurationService: ITerminalConfigurationService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@ITerminalLogService private readonly _logService: ITerminalLogService,
@ITunnelService private readonly _tunnelService: ITunnelService
Expand Down Expand Up @@ -99,7 +100,21 @@ export class TerminalLinkManager extends DisposableStore {
activeTooltipScheduler?.dispose();
}));
this._xterm.options.linkHandler = {
activate: (_, text) => {
allowNonHttpProtocols: true,
activate: (event, text) => {
if (!this._isLinkActivationModifierDown(event)) {
return;
}
// TODO: Support arbitrary schemes
const colonIndex = text.indexOf(':');
if (colonIndex === -1) {
throw new Error(`Could not find scheme in link "${text}"`);
}
const scheme = text.substring(0, colonIndex);
if (this._termninalConfigurationService.config.allowedLinkSchemes.indexOf(scheme) === -1) {
// TODO: Notification with config
throw new Error('Scheme not allowed');
}
this._openers.get(TerminalBuiltinLinkType.Url)?.open({
type: TerminalBuiltinLinkType.Url,
text,
Expand Down

0 comments on commit eca9ac7

Please sign in to comment.