Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(windows): quote Expand-Archive fallback paths that contain apostrophes

Po-Han Shih35a55c5ba0a0
diff --git a/src/helpers/downloadUtils.js b/src/helpers/downloadUtils.js
index 6452ecb16..35b3773df 100644
--- a/src/helpers/downloadUtils.js
+++ b/src/helpers/downloadUtils.js
@@ -433,6 +433,10 @@ async function checkDiskSpace(directory, requiredBytes) {
}
}
+function escapePowerShellSingleQuoted(value) {
+ return String(value).replace(/'/g, "''");
+}
+
async function extractZipWindows(zipPath, destDir) {
try {
await runSystemTar(zipPath, destDir);
@@ -441,19 +445,15 @@ async function extractZipWindows(zipPath, destDir) {
debugLogger.info("tar extraction failed, trying PowerShell", { error: error.message });
}
+ const command =
+ `Expand-Archive -Force -LiteralPath '${escapePowerShellSingleQuoted(zipPath)}' ` +
+ `-DestinationPath '${escapePowerShellSingleQuoted(destDir)}'`;
+
return new Promise((resolve, reject) => {
- execFile(
- "powershell",
- [
- "-NoProfile",
- "-Command",
- `Expand-Archive -Force -Path '${zipPath}' -DestinationPath '${destDir}'`,
- ],
- (psError) => {
- if (psError) reject(new Error(`Zip extraction failed: ${psError.message}`));
- else resolve();
- }
- );
+ execFile("powershell", ["-NoProfile", "-Command", command], (psError) => {
+ if (psError) reject(new Error(`Zip extraction failed: ${psError.message}`));
+ else resolve();
+ });
});
}
diff --git a/test/helpers/extractArchive.test.js b/test/helpers/extractArchive.test.js
index ff641d8c2..d95aa11fa 100644
--- a/test/helpers/extractArchive.test.js
+++ b/test/helpers/extractArchive.test.js
@@ -30,7 +30,9 @@ function freshRequire({ runSystemTar } = {}) {
delete require.cache[downloadUtilsPath];
Module._load = function loadWithMocks(request, parent, isMain) {
- if (request === "electron") return { net: {} };
+ if (request === "electron") {
+ return { net: {}, app: { isPackaged: false, isReady: () => false } };
+ }
if (request === "./systemTar" && runSystemTar) return { runSystemTar };
return originalLoad.call(this, request, parent, isMain);
};
@@ -180,7 +182,7 @@ test("extractArchive falls back to PowerShell when Windows tar rejects a zip arc
args: [
"-NoProfile",
"-Command",
- "Expand-Archive -Force -Path 'C:\\cache\\binary.zip' -DestinationPath 'C:\\cache\\extract'",
+ "Expand-Archive -Force -LiteralPath 'C:\\cache\\binary.zip' -DestinationPath 'C:\\cache\\extract'",
],
},
]);
@@ -190,3 +192,64 @@ test("extractArchive falls back to PowerShell when Windows tar rejects a zip arc
delete require.cache[downloadUtilsPath];
}
});
+
+test("extractArchive PowerShell fallback quotes apostrophe paths safely", async () => {
+ const originalPlatform = Object.getOwnPropertyDescriptor(process, "platform");
+ const originalExecFile = cp.execFile;
+ const execCalls = [];
+
+ Object.defineProperty(process, "platform", { value: "win32" });
+ cp.execFile = (command, args, callback) => {
+ execCalls.push({ command, args });
+ callback(null);
+ };
+
+ const archivePath = "C:\\Users\\O'Brien\\cache\\binary.zip";
+ const destDir = "C:\\Users\\O'Brien\\cache\\extract";
+ const { extractArchive } = freshRequire({
+ runSystemTar: async () => {
+ throw new Error("tar extraction timed out");
+ },
+ });
+
+ try {
+ await extractArchive(archivePath, destDir);
+ assert.equal(execCalls.length, 1);
+ assert.equal(execCalls[0].command, "powershell");
+ assert.deepEqual(execCalls[0].args, [
+ "-NoProfile",
+ "-Command",
+ "Expand-Archive -Force -LiteralPath 'C:\\Users\\O''Brien\\cache\\binary.zip' -DestinationPath 'C:\\Users\\O''Brien\\cache\\extract'",
+ ]);
+ } finally {
+ cp.execFile = originalExecFile;
+ Object.defineProperty(process, "platform", originalPlatform);
+ delete require.cache[downloadUtilsPath];
+ }
+});
+
+test(
+ "extractArchive PowerShell fallback extracts a zip under apostrophe paths",
+ { skip: process.platform !== "win32" },
+ async () => {
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "O'Brien-extract-"));
+ const zipPath = writeZip(tmp, "binary.zip", Buffer.from(ZIP_FIXTURE_B64, "base64"));
+ const dest = path.join(tmp, "out");
+ fs.mkdirSync(dest);
+
+ const { extractArchive } = freshRequire({
+ runSystemTar: async () => {
+ throw new Error("tar extraction timed out");
+ },
+ });
+
+ try {
+ await extractArchive(zipPath, dest);
+ const content = fs.readFileSync(path.join(dest, "test-file.txt"), "utf8");
+ assert.equal(content.trim(), "hello from test");
+ } finally {
+ delete require.cache[downloadUtilsPath];
+ fs.rmSync(tmp, { recursive: true, force: true });
+ }
+ }
+);