Skip to content

Commit 005bb3f

Browse files
committed
chore: fix zip file name sanitization
1 parent 8be5599 commit 005bb3f

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

packages/cli/src/lib/defaults/infra-modules/http/server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"file-saver": "2.0.5",
2020
"jszip": "3.10.1",
2121
"fs-extra": "7.0.1",
22-
"multer": "1.4.5-lts.1"
22+
"multer": "1.4.5-lts.1",
23+
"sanitize-filename": "1.6.3"
2324
},
2425
"devDependencies": {
2526
"@types/express": "4.17.13",

packages/cli/src/lib/defaults/infra-modules/http/server/src/utils/zip.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import JSZip from "jszip";
2+
import sanitize from "sanitize-filename";
23
import fse from "fs-extra";
4+
import path from "path";
35

46
export class Zip {
57
private _zip: JSZip;
@@ -22,8 +24,13 @@ export class Zip {
2224
}
2325

2426
public createZip(sourceDir: string, outputPath: string): Promise<boolean> {
27+
if (!fse.lstatSync(sourceDir).isDirectory()) {
28+
throw new Error(`Zip sourceDir '${sourceDir}' is not a directory.`);
29+
}
30+
2531
fse.readdirSync(sourceDir).forEach(file => {
26-
this._zip.file(file, fse.readFileSync(`${sourceDir}/${file}`))
32+
const filePath = path.join(sourceDir, sanitize(file));
33+
this._zip.file(file, fse.readFileSync(filePath))
2734
})
2835
return this._generateNodeZip(outputPath);
2936
}

0 commit comments

Comments
 (0)