Skip to content

Commit ebd5fb1

Browse files
authored
Git - fix file path parsing issue in askpass (microsoft#257422)
Git - fix file path parsin issue in askpass
1 parent 8ab30c5 commit ebd5fb1

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

extensions/git/src/askpass.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { window, InputBoxOptions, Uri, Disposable, workspace, QuickPickOptions, l10n, LogOutputChannel } from 'vscode';
7-
import { IDisposable, EmptyDisposable, toDisposable } from './util';
7+
import { IDisposable, EmptyDisposable, toDisposable, extractFilePathFromArgs } from './util';
88
import * as path from 'path';
99
import { IIPCHandler, IIPCServer } from './ipc/ipcServer';
1010
import { CredentialsProvider, Credentials } from './api/git';
@@ -108,7 +108,7 @@ export class Askpass implements IIPCHandler, ITerminalEnvironmentProvider {
108108
if (/passphrase/i.test(request)) {
109109
// Commit signing - Enter passphrase:
110110
// Git operation - Enter passphrase for key '/c/Users/<username>/.ssh/id_ed25519':
111-
const file = argv[6]?.replace(/^["']+|["':]+$/g, '');
111+
const file = extractFilePathFromArgs(argv, 6);
112112

113113
this.logger.trace(`[Askpass][handleSSHAskpass] request: ${request}, file: ${file}`);
114114

extensions/git/src/util.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,3 +790,35 @@ export function toDiagnosticSeverity(value: DiagnosticSeverityConfig): Diagnosti
790790
? DiagnosticSeverity.Information
791791
: DiagnosticSeverity.Hint;
792792
}
793+
794+
export function extractFilePathFromArgs(argv: string[], startIndex: number): string {
795+
// Argument doesn't start with a quote
796+
const firstArg = argv[startIndex];
797+
if (!firstArg.match(/^["']/)) {
798+
return firstArg.replace(/^["']+|["':]+$/g, '');
799+
}
800+
801+
// If it starts with a quote, we need to find the matching closing
802+
// quote which might be in a later argument if the path contains
803+
// spaces
804+
const quote = firstArg[0];
805+
806+
// If the first argument ends with the same quote, it's complete
807+
if (firstArg.endsWith(quote) && firstArg.length > 1) {
808+
return firstArg.slice(1, -1);
809+
}
810+
811+
// Concatenate arguments until we find the closing quote
812+
let path = firstArg;
813+
for (let i = startIndex + 1; i < argv.length; i++) {
814+
path = `${path} ${argv[i]}`;
815+
if (argv[i].endsWith(quote)) {
816+
// Found the matching quote
817+
return path.slice(1, -1);
818+
}
819+
}
820+
821+
// If no closing quote was found, remove
822+
// leading quote and return the path as-is
823+
return path.slice(1);
824+
}

0 commit comments

Comments
 (0)