From b336e3863737af078259e40dd1502e8a3083fa8f Mon Sep 17 00:00:00 2001 From: Gared Date: Tue, 10 Sep 2013 21:58:28 +0200 Subject: [PATCH] Add check if uploaded file only contains ascii chars when abiword disabled --- src/node/handler/ImportHandler.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index a155f5c67..281a8d7bf 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -113,6 +113,30 @@ exports.doImport = function(req, res, padId) } }, + function(callback) { + if (!abiword) { + // Read the file with no encoding for raw buffer access. + fs.readFile(destFile, function(err, buf) { + if (err) throw err; + var isAscii = true; + // Check if there are only ascii chars in the uploaded file + for (var i=0, len=buf.length; i 240) { + isAscii=false; + break; + } + } + if (isAscii) { + callback(); + } else { + callback("uploadFailed"); + } + }); + } else { + callback(); + } + }, + //get the pad object function(callback) { padManager.getPad(padId, function(err, _pad){