git: validate URI for clone command (#149180)
Co-authored-by: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com>pull/149194/head
parent
8965a02114
commit
c5da5332d5
|
@ -7,6 +7,8 @@ import { UriHandler, Uri, window, Disposable, commands } from 'vscode';
|
|||
import { dispose } from './util';
|
||||
import * as querystring from 'querystring';
|
||||
|
||||
const schemes = new Set(['file', 'git', 'http', 'https', 'ssh']);
|
||||
|
||||
export class GitProtocolHandler implements UriHandler {
|
||||
|
||||
private disposables: Disposable[] = [];
|
||||
|
@ -26,9 +28,27 @@ export class GitProtocolHandler implements UriHandler {
|
|||
|
||||
if (!data.url) {
|
||||
console.warn('Failed to open URI:', uri);
|
||||
return;
|
||||
}
|
||||
|
||||
commands.executeCommand('git.clone', data.url);
|
||||
if (Array.isArray(data.url) && data.url.length === 0) {
|
||||
console.warn('Failed to open URI:', uri);
|
||||
return;
|
||||
}
|
||||
|
||||
let cloneUri: Uri;
|
||||
try {
|
||||
cloneUri = Uri.parse(Array.isArray(data.url) ? data.url[0] : data.url, true);
|
||||
if (!schemes.has(cloneUri.scheme.toLowerCase())) {
|
||||
throw new Error('Unsupported scheme.');
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
console.warn('Invalid URI:', uri);
|
||||
return;
|
||||
}
|
||||
|
||||
commands.executeCommand('git.clone', cloneUri.toString(true));
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
|
Loading…
Reference in New Issue