@@ -316,8 +316,11 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
316
316
}
317
317
318
318
// Pass the sequence along to the capability
319
- const [ command , ...args ] = data . split ( ';' ) ;
320
- switch ( command ) {
319
+ const argsIndex = data . indexOf ( ';' ) ;
320
+ const sequenceCommand = argsIndex === - 1 ? data : data . substring ( 0 , argsIndex ) ;
321
+ // Cast to strict checked index access
322
+ const args : ( string | undefined ) [ ] = argsIndex === - 1 ? [ ] : data . substring ( argsIndex + 1 ) . split ( ';' ) ;
323
+ switch ( sequenceCommand ) {
321
324
case VSCodeOscPt . PromptStart :
322
325
this . _createOrGetCommandDetection ( this . _terminal ) . handlePromptStart ( ) ;
323
326
return true ;
@@ -328,18 +331,21 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
328
331
this . _createOrGetCommandDetection ( this . _terminal ) . handleCommandExecuted ( ) ;
329
332
return true ;
330
333
case VSCodeOscPt . CommandFinished : {
331
- const exitCode = args . length === 1 ? parseInt ( args [ 0 ] ) : undefined ;
334
+ const arg0 = args [ 0 ] ;
335
+ const exitCode = arg0 !== undefined ? parseInt ( arg0 ) : undefined ;
332
336
this . _createOrGetCommandDetection ( this . _terminal ) . handleCommandFinished ( exitCode ) ;
333
337
return true ;
334
338
}
335
339
case VSCodeOscPt . CommandLine : {
340
+ const arg0 = args [ 0 ] ;
341
+ const arg1 = args [ 1 ] ;
336
342
let commandLine : string ;
337
- if ( args . length >= 1 || args . length <= 2 ) {
338
- commandLine = deserializeMessage ( args [ 0 ] ) ;
343
+ if ( arg0 !== undefined ) {
344
+ commandLine = deserializeMessage ( arg0 ) ;
339
345
} else {
340
346
commandLine = '' ;
341
347
}
342
- this . _createOrGetCommandDetection ( this . _terminal ) . setCommandLine ( commandLine , args [ 1 ] === this . _nonce ) ;
348
+ this . _createOrGetCommandDetection ( this . _terminal ) . setCommandLine ( commandLine , arg1 === this . _nonce ) ;
343
349
return true ;
344
350
}
345
351
case VSCodeOscPt . ContinuationStart : {
@@ -359,7 +365,8 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
359
365
return true ;
360
366
}
361
367
case VSCodeOscPt . Property : {
362
- const deserialized = args . length ? deserializeMessage ( args [ 0 ] ) : '' ;
368
+ const arg0 = args [ 0 ] ;
369
+ const deserialized = arg0 !== undefined ? deserializeMessage ( arg0 ) : '' ;
363
370
const { key, value } = parseKeyValueAssignment ( deserialized ) ;
364
371
if ( value === undefined ) {
365
372
return true ;
@@ -539,10 +546,14 @@ export function parseKeyValueAssignment(message: string): { key: string; value:
539
546
}
540
547
541
548
542
- export function parseMarkSequence ( sequence : string [ ] ) : { id ?: string ; hidden ?: boolean } {
549
+ export function parseMarkSequence ( sequence : ( string | undefined ) [ ] ) : { id ?: string ; hidden ?: boolean } {
543
550
let id = undefined ;
544
551
let hidden = false ;
545
552
for ( const property of sequence ) {
553
+ // Sanity check, this shouldn't happen in practice
554
+ if ( property === undefined ) {
555
+ continue ;
556
+ }
546
557
if ( property === 'Hidden' ) {
547
558
hidden = true ;
548
559
}
0 commit comments