Skip to content
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

make sure args are defined #181941

Closed
wants to merge 13 commits into from
26 changes: 18 additions & 8 deletions src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,15 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
}

// Pass the sequence along to the capability
const [command, ...args] = data.split(';');
const dataArr = data.split(';');
if (!dataArr.length) {
return false;
}
const command = dataArr[0];
const args: string[] | undefined = dataArr.length > 1 ? dataArr.slice(1) : undefined;
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
if (args && args?.length > 2) {
return false;
}
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
switch (command) {
case VSCodeOscPt.PromptStart:
this._createOrGetCommandDetection(this._terminal).handlePromptStart();
Expand All @@ -328,17 +336,17 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
this._createOrGetCommandDetection(this._terminal).handleCommandExecuted();
return true;
case VSCodeOscPt.CommandFinished: {
const exitCode = args.length === 1 ? parseInt(args[0]) : undefined;
const exitCode = command ? parseInt(command) : undefined;
this._createOrGetCommandDetection(this._terminal).handleCommandFinished(exitCode);
return true;
}
case VSCodeOscPt.CommandLine: {
const commandLine: string | undefined = args.length ? deserializeMessage(args[0]) : undefined;
const isTrusted = args.length > 1 ? args[1] === this._nonce : false;
const commandLine: string | undefined = command ? deserializeMessage(command) : undefined;
const isTrusted = args ? args[1] === this._nonce : false;
if (commandLine) {
this._createOrGetCommandDetection(this._terminal).setCommandLine(commandLine, isTrusted);
}
return !!commandLine && args.length < 3;
return !!commandLine;
}
case VSCodeOscPt.ContinuationStart: {
this._createOrGetCommandDetection(this._terminal).handleContinuationStart();
Expand All @@ -357,7 +365,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
return true;
}
case VSCodeOscPt.Property: {
const deserialized = args.length ? deserializeMessage(args[0]) : '';
const deserialized = args?.length ? deserializeMessage(args[0]) : '';
const { key, value } = parseKeyValueAssignment(deserialized);
if (value === undefined) {
return true;
Expand All @@ -379,8 +387,10 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
}
}
case VSCodeOscPt.SetMark: {
this._createOrGetBufferMarkDetection(this._terminal).addMark(parseMarkSequence(args));
return true;
if (args) {
this._createOrGetBufferMarkDetection(this._terminal).addMark(parseMarkSequence(args));
}
return !!args;
}
}

Expand Down