@@ -408,24 +408,17 @@ export async function promptForValidRepoURI(): Promise<string> {
408
408
}
409
409
410
410
/**
411
- * Prompts for a valid extension root.
411
+ * Prompts for an extension root.
412
412
*
413
413
* @param defaultRoot the default extension root
414
414
*/
415
- export async function promptForValidExtensionRoot ( defaultRoot : string ) : Promise < string > {
416
- let rootIsValid = false ;
417
- let extensionRoot = "" ;
418
- while ( ! rootIsValid ) {
419
- extensionRoot = await promptOnce ( {
420
- type : "input" ,
421
- message :
422
- "Enter this extension's root directory in the repo (defaults to previous root if set):" ,
423
- default : defaultRoot ,
424
- } ) ;
425
- // TODO: Add real directory path validation.
426
- rootIsValid = true ;
427
- }
428
- return extensionRoot ;
415
+ export async function promptForExtensionRoot ( defaultRoot : string ) : Promise < string > {
416
+ return await promptOnce ( {
417
+ type : "input" ,
418
+ message :
419
+ "Enter this extension's root directory in the repo (defaults to previous root if set):" ,
420
+ default : defaultRoot ,
421
+ } ) ;
429
422
}
430
423
431
424
/**
@@ -817,11 +810,17 @@ export async function uploadExtensionVersionFromGitHubSource(args: {
817
810
if ( ! extensionRoot ) {
818
811
const defaultRoot = "/" ;
819
812
if ( ! args . nonInteractive ) {
820
- extensionRoot = await promptForValidExtensionRoot ( defaultRoot ) ;
813
+ extensionRoot = await promptForExtensionRoot ( defaultRoot ) ;
821
814
} else {
822
815
extensionRoot = defaultRoot ;
823
816
}
824
817
}
818
+ // Normalize root path and strip leading and trailing slashes and all `../`.
819
+ const normalizedRoot = path
820
+ . normalize ( extensionRoot )
821
+ . replaceAll ( / ^ \/ | \/ $ / g, "" )
822
+ . replaceAll ( / ^ ( \. \. \/ ) * / g, "" ) ;
823
+ extensionRoot = normalizedRoot || "/" ;
825
824
826
825
// Prompt for source ref and default to HEAD.
827
826
let sourceRef = args . sourceRef ;
0 commit comments