style: format archive extraction changes
This commit is contained in:
parent
34e9448d08
commit
ecb5120ece
@ -60,9 +60,9 @@ describe("archive utils", () => {
|
||||
await fs.writeFile(archivePath, await zip.generateAsync({ type: "nodebuffer" }));
|
||||
|
||||
await fs.mkdir(extractDir, { recursive: true });
|
||||
await expect(extractArchive({ archivePath, destDir: extractDir, timeoutMs: 5_000 })).rejects.toThrow(
|
||||
/escapes destination/i,
|
||||
);
|
||||
await expect(
|
||||
extractArchive({ archivePath, destDir: extractDir, timeoutMs: 5_000 }),
|
||||
).rejects.toThrow(/escapes destination/i);
|
||||
await expect(fs.stat(path.join(siblingDir, "pwned.txt"))).rejects.toThrow();
|
||||
});
|
||||
|
||||
|
||||
@ -65,7 +65,9 @@ function ensureTrailingSep(filePath: string): string {
|
||||
return filePath.endsWith(path.sep) ? filePath : `${filePath}${path.sep}`;
|
||||
}
|
||||
|
||||
async function normalizeDestRoot(destDir: string): Promise<{ destRoot: string; destRootLower?: string }> {
|
||||
async function normalizeDestRoot(
|
||||
destDir: string,
|
||||
): Promise<{ destRoot: string; destRootLower?: string }> {
|
||||
await fs.mkdir(destDir, { recursive: true });
|
||||
const destReal = await fs.realpath(destDir);
|
||||
const destRoot = ensureTrailingSep(destReal);
|
||||
@ -77,7 +79,9 @@ async function normalizeDestRoot(destDir: string): Promise<{ destRoot: string; d
|
||||
async function extractZip(params: { archivePath: string; destDir: string }): Promise<void> {
|
||||
const { destRoot, destRootLower } = await normalizeDestRoot(params.destDir);
|
||||
const startsWithDest = (targetPath: string): boolean =>
|
||||
destRootLower ? targetPath.toLowerCase().startsWith(destRootLower) : targetPath.startsWith(destRoot);
|
||||
destRootLower
|
||||
? targetPath.toLowerCase().startsWith(destRootLower)
|
||||
: targetPath.startsWith(destRoot);
|
||||
|
||||
const buffer = await fs.readFile(params.archivePath);
|
||||
const zip = await JSZip.loadAsync(buffer);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user