From cadb83ac5af0911e722812d934d3133735d46ced Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 19 Jan 2015 02:51:32 +0000 Subject: [PATCH] bumpage --- src/node/db/API.js | 11 ++++- src/node/handler/ImportHandler.js | 8 ++-- src/node/utils/ImportHtml.js | 2 +- tests/backend/specs/api/pad.js | 67 +++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 7 deletions(-) diff --git a/src/node/db/API.js b/src/node/db/API.js index a9df2a12f..07127309d 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -410,7 +410,16 @@ exports.setHTML = function(padID, html, callback) if(ERR(err, callback)) return; // add a new changeset with the new html to the pad - importHtml.setPadHTML(pad, cleanText(html), callback); + importHtml.setPadHTML(pad, cleanText(html), function(e){ + if(e){ + callback(new customError("HTML is malformed","apierror")); + return; + }else{ + //update the clients on the pad + padMessageHandler.updatePadClients(pad, callback); + return; + } + }); //update the clients on the pad padMessageHandler.updatePadClients(pad, callback); diff --git a/src/node/handler/ImportHandler.js b/src/node/handler/ImportHandler.js index a511637cc..676986510 100644 --- a/src/node/handler/ImportHandler.js +++ b/src/node/handler/ImportHandler.js @@ -232,11 +232,9 @@ exports.doImport = function(req, res, padId) if(!directDatabaseAccess){ var fileEnding = path.extname(srcFile).toLowerCase(); if (abiword || fileEnding == ".htm" || fileEnding == ".html") { - try{ - importHtml.setPadHTML(pad, text); - }catch(e){ - apiLogger.warn("Error importing, possibly caused by malformed HTML"); - } + importHtml.setPadHTML(pad, text, function(e){ + if(e) apiLogger.warn("Error importing, possibly caused by malformed HTML"); + }); } else { pad.setText(text); } diff --git a/src/node/utils/ImportHtml.js b/src/node/utils/ImportHtml.js index 59802f9bf..652e7fccd 100644 --- a/src/node/utils/ImportHtml.js +++ b/src/node/utils/ImportHtml.js @@ -40,7 +40,7 @@ function setPadHTML(pad, html, callback) cc.collectContent(doc); }catch(e){ apiLogger.warn("HTML was not properly formed", e); - return; // We don't process the HTML because it was bad.. + return callback(e); // We don't process the HTML because it was bad.. } var result = cc.finish(); diff --git a/tests/backend/specs/api/pad.js b/tests/backend/specs/api/pad.js index 52e7c9170..012ce4238 100644 --- a/tests/backend/specs/api/pad.js +++ b/tests/backend/specs/api/pad.js @@ -12,6 +12,7 @@ var apiVersion = 1; var testPadId = makeid(); var lastEdited = ""; var text = generateLongText(); +var ULhtml = '
'; describe('Connectivity', function(){ it('errors if can not connect', function(done) { @@ -71,6 +72,9 @@ describe('Permission', function(){ -> movePad(newPadID, originalPadId) -- Should provide consistant pad data -> getText(originalPadId) -- Should be "hello world" -> getLastEdited(padID) -- Should not be 0 + -> setHTML(padID) -- Should fail on invalid HTML + -> setHTML(padID) *3 -- Should fail on invalid HTML + -> getHTML(padID) -- Should return HTML close to posted HTML */ @@ -390,6 +394,69 @@ describe('getLastEdited', function(){ }); }) + +describe('setHTML', function(){ + it('Sets the HTML of a Pad attempting to pass ugly HTML', function(done) { + var html = "
Hello HTML
"; + api.get(endPoint('setHTML')+"&padID="+testPadId+"&html="+html) + .expect(function(res){ + if(res.body.code !== 1) throw new Error("Allowing crappy HTML to be imported") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +describe('setHTML', function(){ + it('Sets the HTML of a Pad with a bunch of weird unordered lists inserted', function(done) { + api.get(endPoint('setHTML')+"&padID=test&html="+ULhtml) + .expect(function(res){ + if(res.body.code !== 0) throw new Error("List HTML cant be imported") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +describe('getHTML', function(){ + // will fail due to https://github.com/ether/etherpad-lite/issues/1604 + // reminder to self this is how the HTML looks + // + //
+ // + // It will look right in the browser but the export will get it horriby wrong + + // This is what the export puts out + // + //
+ // + //
+ + it('Gets the HTML of a Pad with a bunch of weird unordered lists inserted', function(done) { + api.get(endPoint('getHTML')+"&padID=test") + .expect(function(res){ + console.log(res.body.data.html); + if(res.body.data !== ULhtml) throw new Error("Imported HTML does not match served HTML") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + + /* -> movePadForce Test