Fixed international download filenames.
Ylian Saint-Hilaire committed
Feb 4, 2021 at 12:27 UTC
7a34e8c169bf391e07b0d0370729ed467275e5e7
3 files changed
+5
-5
meshdevicefile.js
+2
-2
@@ -294,9 +294,9 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us
294
// Set the content disposition header for a HTTP response.
295
// Because the filename can't have any special characters in it, we need to be extra careful.
296
function setContentDispositionHeader(res, type, name, size, altname) {
297
- if (name != null) { name = require('path').basename(name).split('\\').join('').split('/').join('').split(':').join('').split('*').join('').split('?').join('').split('"').join('').split('<').join('').split('>').join('').split('|').join('').split(' ').join('').split('\'').join(''); } else { name = altname; }
297
+ if (name != null) { name = require('path').basename(name).split('\\').join('').split('/').join('').split(':').join('').split('*').join('').split('?').join('').split('"').join('').split('<').join('').split('>').join('').split('|').join('').split('\'').join(''); } else { name = altname; }
298
try {
299
- var x = { 'Cache-Control': 'no-store', 'Content-Type': type, 'Content-Disposition': 'attachment; filename="' + name + '"' };
299
+ var x = { 'Cache-Control': 'no-store', 'Content-Type': type, 'Content-Disposition': 'attachment; filename*="' + encodeURIComponent(name) + '"; filename="' + altname + '"' };
300
if (typeof size == 'number') { x['Content-Length'] = size; }
301
res.set(x);
302
} catch (ex) {
redirserver.js
+1
-1
@@ -53,7 +53,7 @@ module.exports.CreateRedirServer = function (parent, db, args, func) {
53
obj.app.get('/MeshServerRootCert.cer', function (req, res) {
54
// The redirection server starts before certificates are loaded, make sure to handle the case where no certificate is loaded now.
55
if (obj.certificates != null) {
56
- res.set({ 'Cache-Control': 'no-store', 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment; filename="' + obj.certificates.RootName + '.cer"' });
56
+ res.set({ 'Cache-Control': 'no-store', 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment; filename*="' + encodeURIComponent(obj.certificates.RootName) + '.cer"' });
57
var rootcert = obj.certificates.root.cert;
58
var i = rootcert.indexOf('-----BEGIN CERTIFICATE-----\r\n');
59
if (i >= 0) { rootcert = rootcert.substring(i + 29); }
webserver.js
+2
-2
@@ -6705,9 +6705,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
6705
// Set the content disposition header for a HTTP response.
6706
// Because the filename can't have any special characters in it, we need to be extra careful.
6707
function setContentDispositionHeader(res, type, name, size, altname) {
6708
- var name = require('path').basename(name).split('\\').join('').split('/').join('').split(':').join('').split('*').join('').split('?').join('').split('"').join('').split('<').join('').split('>').join('').split('|').join('').split(' ').join('').split('\'').join('');
6708
+ var name = require('path').basename(name).split('\\').join('').split('/').join('').split(':').join('').split('*').join('').split('?').join('').split('"').join('').split('<').join('').split('>').join('').split('|').join('').split('\'').join('');
6709
try {
6710
- var x = { 'Cache-Control': 'no-store', 'Content-Type': type, 'Content-Disposition': 'attachment; filename="' + name + '"' };
6710
+ var x = { 'Cache-Control': 'no-store', 'Content-Type': type, 'Content-Disposition': 'attachment; filename*="' + encodeURIComponent(name) + '"; filename="' + altname + '"' };
6711
if (typeof size == 'number') { x['Content-Length'] = size; }
6712
res.set(x);
6713
} catch (ex) {