From 0d4a77f4b5dcdd6b969c42428089c0137c6f7ef4 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Wed, 6 Mar 2019 14:25:55 +0100 Subject: [PATCH] Sanitize project name before using it in directory name --- lib/tasks/generateJsdoc.js | 4 +++- test/lib/tasks/generateJsdoc.js | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/tasks/generateJsdoc.js b/lib/tasks/generateJsdoc.js index 2993e3d14..8c30c2e19 100644 --- a/lib/tasks/generateJsdoc.js +++ b/lib/tasks/generateJsdoc.js @@ -82,9 +82,11 @@ async function createTmpDirs(projectName) { * @returns {Promise} Promise resolving with path of the temporary directory */ function createTmpDir(projectName) { + // Remove all non alpha-num characters from project name + const sanitizedProjectName = projectName.replace(/[^A-Za-z0-9]/g, ""); return new Promise((resolve, reject) => { tmp.dir({ - prefix: `ui5-tooling-tmp-jsdoc-${projectName}-`, + prefix: `ui5-tooling-tmp-jsdoc-${sanitizedProjectName}-`, // keep: true, unsafeCleanup: true }, (err, path) => { diff --git a/test/lib/tasks/generateJsdoc.js b/test/lib/tasks/generateJsdoc.js index fa1cd8663..a781399a8 100644 --- a/test/lib/tasks/generateJsdoc.js +++ b/test/lib/tasks/generateJsdoc.js @@ -17,10 +17,10 @@ test.afterEach.always((t) => { test.serial("createTmpDir successful", async (t) => { t.context.tmpStub.callsArgWithAsync(1, undefined, "some/path"); - const res = await generateJsdoc._createTmpDir("some.namespace"); + const res = await generateJsdoc._createTmpDir("som$e.nam3/space"); // non alphanum characters get removed t.deepEqual(t.context.tmpStub.callCount, 1, "Tmp dir is called once"); - t.deepEqual(t.context.tmpStub.getCall(0).args[0].prefix, "ui5-tooling-tmp-jsdoc-some.namespace-"); + t.deepEqual(t.context.tmpStub.getCall(0).args[0].prefix, "ui5-tooling-tmp-jsdoc-somenam3space-"); t.deepEqual(res, {path: "some/path"}, "Correct path returned"); }); @@ -30,7 +30,7 @@ test.serial("createTmpDir error", async (t) => { const res = await t.throws(generateJsdoc._createTmpDir("some.namespace")); t.deepEqual(t.context.tmpStub.callCount, 1, "Tmp dir is called once"); - t.deepEqual(t.context.tmpStub.getCall(0).args[0].prefix, "ui5-tooling-tmp-jsdoc-some.namespace-"); + t.deepEqual(t.context.tmpStub.getCall(0).args[0].prefix, "ui5-tooling-tmp-jsdoc-somenamespace-"); t.deepEqual(res, {message: "Dir creation failed"}, "Dir creation failed"); });