Fix location of removing dots

This commit is contained in:
Koen Vlaswinkel
2024-03-11 14:14:28 +01:00
parent bbc09f3ae5
commit 7681a56a16
2 changed files with 10 additions and 4 deletions

View File

@@ -30,14 +30,15 @@ export function createFilenameFromString(
// Remove any leading or trailing hyphens or dots
fileName = fileName.replaceAll(/^[.-]+|[.-]+$/g, "");
// Replace dots by hyphens if dots are not allowed
if (removeDots) {
fileName = fileName.replaceAll(/\./g, "-");
}
// Remove any duplicate hyphens
fileName = fileName.replaceAll(/-{2,}/g, "-");
// Remove any duplicate dots
fileName = fileName.replaceAll(/\.{2,}/g, ".");
if (removeDots) {
fileName = fileName.replaceAll(/\./g, "-");
}
return fileName;
}

View File

@@ -58,6 +58,11 @@ describe("createFilenameFromString", () => {
filename: "unetworking-uwebsockets.js",
filenameWithoutDots: "unetworking-uwebsockets-js",
},
{
input: "github/.vscode-codeql",
filename: "github-.vscode-codeql",
filenameWithoutDots: "github-vscode-codeql",
},
];
test.each(testCases)(