Trim whitespace and slashes in pack names

This commit is contained in:
Koen Vlaswinkel
2024-04-10 15:08:35 +02:00
parent bf9bfb13b7
commit 3f4ed48787
2 changed files with 23 additions and 0 deletions

View File

@@ -17,6 +17,17 @@ export function formatPackName(packName: ExtensionPackName): string {
export function sanitizePackName(userPackName: string): ExtensionPackName {
let packName = userPackName;
packName = packName.trim();
while (packName.startsWith("/")) {
packName = packName.slice(1);
}
while (packName.endsWith("/")) {
packName = packName.slice(0, -1);
}
if (!packName.includes("/")) {
packName = `pack/${packName}`;
}

View File

@@ -58,6 +58,18 @@ describe("sanitizePackName", () => {
name: "a/b--d--e-d-csharp",
expected: "a/b-d-e-d-csharp",
},
{
name: "/github/vscode-codeql",
expected: "github/vscode-codeql",
},
{
name: "github/vscode-codeql/",
expected: "github/vscode-codeql",
},
{
name: "///github/vscode-codeql///",
expected: "github/vscode-codeql",
},
];
test.each(testCases)(