Escape the filename arguments to zip and tar correctly on Windows

pull/315/head
Chris Brown 2016-06-06 15:37:32 +01:00
rodzic dbf1d72d1c
commit 6440ef1eb8
1 zmienionych plików z 14 dodań i 10 usunięć

Wyświetl plik

@ -46,9 +46,9 @@ define(function(require, exports, module) {
}
var filenameHeader = "attachment; filename*=utf-8''" + escape(filename);
var process;
var proc;
req.on("close", function() {
if (process) process.kill();
if (proc) proc.kill();
});
if (req.uri.query.isfile) {
@ -113,22 +113,26 @@ define(function(require, exports, module) {
paths.forEach(function(path) {
if (!path) return;
path = Path.relative(cwd, path);
// Single quote the path to escape unusual characters, and manually escape single quotes.
path = "'" + path.replace(/'/, "'\\''") + "'";
if (/win/.test(process.platform)) {
// Quote the path to escape unusual characters and spaces.
// NB: Double quotes are illegal within the actual path on Windows.
path = '"' + path + '"';
}
args.push(path);
});
vfs.spawn(executable, {
args: args,
cwd: cwd
cwd: cwd,
windowsVerbatimArguments: true // Prevents Node from escaping the double quotes added above.
}, function (err, meta) {
if (err)
return next(err);
process = meta.process;
proc = meta.process;
// once we receive data on stdout pipe it to the response
process.stdout.once("data", function (data) {
proc.stdout.once("data", function (data) {
if (res.headerSent)
return;
@ -137,15 +141,15 @@ define(function(require, exports, module) {
"Content-Disposition": filenameHeader
});
res.write(data);
process.stdout.pipe(res);
proc.stdout.pipe(res);
});
var stderr = "";
process.stderr.on("data", function (data) {
proc.stderr.on("data", function (data) {
stderr += data;
});
process.on("exit", function(code, signal) {
proc.on("exit", function(code, signal) {
if (res.headerSent)
return;