From 1a430199569aa56a78acee70f654655ec8ac7e26 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sat, 21 Mar 2020 23:14:05 +0000 Subject: [PATCH] ImportHandler: instead of failing (badly) when a non Ascii code is uploaded just convert it then convert it back This should mitigate the risk. --- src/node/handler/ImportHandler.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index e62cb94175f..ef6016782f2 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -171,18 +171,6 @@ async function doImport(req, res, padId) } } - if (!useConvertor && !req.directDatabaseAccess) { - // Read the file with no encoding for raw buffer access. - let buf = await fsp_readFile(destFile); - - // Check if there are only ascii chars in the uploaded file - let isAscii = ! Array.prototype.some.call(buf, c => (c > 240)); - - if (!isAscii) { - throw "uploadFailed"; - } - } - // get the pad object let pad = await padManager.getPad(padId); @@ -192,6 +180,9 @@ async function doImport(req, res, padId) if (!req.directDatabaseAccess) { text = await fsp_readFile(destFile, "utf8"); + let bytelike = unescape(encodeURIComponent(text)); + text = decodeURIComponent(escape(bytelike)); + /* * The tag needs to be stripped out, otherwise it is appended to the * pad.