Trim whitespace and slashes in pack names
This commit is contained in:
@@ -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}`;
|
||||
}
|
||||
|
||||
@@ -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)(
|
||||
|
||||
Reference in New Issue
Block a user