Skip to content

Commit 654e884

Browse files
authored
Normalized extension root path before usage in ext:dev:upload. (#6054)
* Normalized extension root path before usage. * Update CHANGELOG.md * Update publisherApi.ts * Update extensionsHelper.ts * Update CHANGELOG.md * Replaced join() with normalize() and fixed regex. * Update extensionsHelper.ts * Update extensionsHelper.ts
1 parent ac28f26 commit 654e884

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- Increased extension instance create poll timeout to 1h to match backend (#5969).
22
- Refactored `ext:install` to use the latest extension metadata. (#5997)
3+
- Normalized extension root path before usage in `ext:dev:upload`. (#6054)

src/extensions/extensionsHelper.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -408,24 +408,17 @@ export async function promptForValidRepoURI(): Promise<string> {
408408
}
409409

410410
/**
411-
* Prompts for a valid extension root.
411+
* Prompts for an extension root.
412412
*
413413
* @param defaultRoot the default extension root
414414
*/
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+
});
429422
}
430423

431424
/**
@@ -817,11 +810,17 @@ export async function uploadExtensionVersionFromGitHubSource(args: {
817810
if (!extensionRoot) {
818811
const defaultRoot = "/";
819812
if (!args.nonInteractive) {
820-
extensionRoot = await promptForValidExtensionRoot(defaultRoot);
813+
extensionRoot = await promptForExtensionRoot(defaultRoot);
821814
} else {
822815
extensionRoot = defaultRoot;
823816
}
824817
}
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 || "/";
825824

826825
// Prompt for source ref and default to HEAD.
827826
let sourceRef = args.sourceRef;

src/extensions/publisherApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export async function createExtensionVersionFromGitHubSource(args: {
205205
ExtensionVersion
206206
>(`/${refs.toExtensionName(ref)}/versions:createFromSource`, {
207207
versionId: ref.version,
208-
extensionRoot: args.extensionRoot ?? "/",
208+
extensionRoot: args.extensionRoot || "/",
209209
githubRepositorySource: {
210210
uri: args.repoUri,
211211
sourceRef: args.sourceRef,

0 commit comments

Comments
 (0)