diff options
author | John McLear <john@mclear.co.uk> | 2013-12-16 03:08:42 -0800 |
---|---|---|
committer | John McLear <john@mclear.co.uk> | 2013-12-16 03:08:42 -0800 |
commit | 7d47d91a08aca73b38af7c8ff46d0465a9c51a0d (patch) | |
tree | 04d4444ccb27a9c21f877829226187891648c85b /src | |
parent | 7c4479d5aa2ff7fa860cbe0f92f8dacbbe48781d (diff) | |
parent | 3d8edef9261b9793027bc999759f3b7e094aacd5 (diff) | |
download | etherpad-lite-7d47d91a08aca73b38af7c8ff46d0465a9c51a0d.zip |
Merge pull request #1514 from ether/dont-die-on-bad-html
dont die on bad html but only warn to api logger but dont tell client th...
Diffstat (limited to 'src')
-rw-r--r-- | src/node/db/API.js | 21 | ||||
-rw-r--r-- | src/node/utils/ImportHtml.js | 15 |
2 files changed, 29 insertions, 7 deletions
diff --git a/src/node/db/API.js b/src/node/db/API.js index 349953cb..98bc8029 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -361,6 +361,8 @@ exports.getHTML = function(padID, rev, callback) exportHtml.getPadHTML(pad, rev, function(err, html) { if(ERR(err, callback)) return; + html = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head + html += "</body></html>"; data = {html: html}; callback(null, data); }); @@ -371,6 +373,8 @@ exports.getHTML = function(padID, rev, callback) exportHtml.getPadHTML(pad, undefined, function (err, html) { if(ERR(err, callback)) return; + html = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head + html += "</body></html>"; data = {html: html}; callback(null, data); }); @@ -378,15 +382,30 @@ exports.getHTML = function(padID, rev, callback) }); } +/** +setHTML(padID, html) sets the text of a pad based on HTML + +Example returns: + +{code: 0, message:"ok", data: null} +{code: 1, message:"padID does not exist", data: null} +*/ exports.setHTML = function(padID, html, callback) { + //html is required + if(typeof html != "string") + { + callback(new customError("html is no string","apierror")); + return; + } + //get the pad getPadSafe(padID, true, function(err, pad) { if(ERR(err, callback)) return; // add a new changeset with the new html to the pad - importHtml.setPadHTML(pad, cleanText(html)); + importHtml.setPadHTML(pad, cleanText(html), callback); //update the clients on the pad padMessageHandler.updatePadClients(pad, callback); diff --git a/src/node/utils/ImportHtml.js b/src/node/utils/ImportHtml.js index 322e567e..abba2ac1 100644 --- a/src/node/utils/ImportHtml.js +++ b/src/node/utils/ImportHtml.js @@ -25,11 +25,6 @@ function setPadHTML(pad, html, callback) { var apiLogger = log4js.getLogger("ImportHtml"); - // Clean the pad. This makes the rest of the code easier - // by several orders of magnitude. - pad.setText(""); - var padText = pad.text(); - // Parse the incoming HTML with jsdom try{ var doc = jsdom(html.replace(/>\n+</g, '><')); @@ -44,8 +39,15 @@ function setPadHTML(pad, html, callback) // Convert a dom tree into a list of lines and attribute liens // using the content collector object var cc = contentcollector.makeContentCollector(true, null, pad.pool); - cc.collectContent(doc.childNodes[0]); + try{ // we use a try here because if the HTML is bad it will blow up + cc.collectContent(doc.childNodes[0]); + }catch(e){ + apiLogger.warn("HTML was not properly formed", e); + return; // We don't process the HTML because it was bad.. + } + var result = cc.finish(); + apiLogger.debug('Lines:'); var i; for (i = 0; i < result.lines.length; i += 1) @@ -90,6 +92,7 @@ function setPadHTML(pad, html, callback) // the changeset is ready! var theChangeset = builder.toString(); apiLogger.debug('The changeset: ' + theChangeset); + pad.setText(""); pad.appendRevision(theChangeset); } |