mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-28 11:26:16 -04:00
fix commenting
This commit is contained in:
parent
444bbf4cbc
commit
7708460faf
4 changed files with 53 additions and 9 deletions
|
@ -408,12 +408,18 @@ exports.setHTML = function(padID, html, callback)
|
|||
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), 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);
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,9 +22,8 @@ var cheerio = require("cheerio");
|
|||
function setPadHTML(pad, html, callback)
|
||||
{
|
||||
var apiLogger = log4js.getLogger("ImportHtml");
|
||||
|
||||
console.warn("setting padhtml");
|
||||
var $ = cheerio.load(html);
|
||||
|
||||
// Appends a line break, used by Etherpad to ensure a caret is available
|
||||
// below the last line of an import
|
||||
$('body').append("<p></p>");
|
||||
|
@ -40,7 +39,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();
|
||||
|
@ -91,6 +90,7 @@ function setPadHTML(pad, html, callback)
|
|||
apiLogger.debug('The changeset: ' + theChangeset);
|
||||
pad.setText("");
|
||||
pad.appendRevision(theChangeset);
|
||||
callback();
|
||||
}
|
||||
|
||||
exports.setPadHTML = setPadHTML;
|
||||
|
|
|
@ -61,6 +61,9 @@ describe('Permission', function(){
|
|||
-> setText(padId)
|
||||
-> getLastEdited(padID) -- Should be when setText was performed
|
||||
-> padUsers(padID) -- Should be when setText was performed
|
||||
-> setHTML(padID) -- Should fail on invalid HTML
|
||||
-> setHTML(padID) -- Should fail on invalid HTML
|
||||
-> getHTML(padID) -- Should return HTML close to posted HTML
|
||||
*/
|
||||
|
||||
describe('deletePad', function(){
|
||||
|
@ -265,6 +268,42 @@ describe('padUsers', function(){
|
|||
});
|
||||
})
|
||||
|
||||
describe('setHTML', function(){
|
||||
it('Sets the HTML of a Pad', function(done) {
|
||||
var html = "<!DOCTYPE html><html><head><title>Hello HTML</title></head><body<p>Hello World!</p></body></html>";
|
||||
api.get(endPoint('setHTML')+"&padID="+testPadId+"&html="+html)
|
||||
.expect(function(res){
|
||||
if(res.body.code !== 0) throw new Error("Error importing HTML")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('setHTML', function(){
|
||||
it('Sets the HTML of a Pad attempting to pass ugly HTML', function(done) {
|
||||
var html = "<div><b>Hello HTML</title></head></div>";
|
||||
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 attempting to pass ugly HTML', function(done) {
|
||||
var html = "<!DOCTYPE html><html><head></head><body><ul><li>Hello World!</li><li>foo</li></ul></body></html>";
|
||||
api.get(endPoint('setHTML')+"&padID=test&html="+html)
|
||||
.expect(function(res){
|
||||
if(res.body.code !== 0) throw new Error("List HTML cant be imported")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
|
||||
var endPoint = function(point){
|
||||
|
|
|
@ -5,7 +5,6 @@ var assert = require('assert')
|
|||
path = require('path');
|
||||
|
||||
var filePath = path.join(__dirname, '../../../../APIKEY.txt');
|
||||
|
||||
var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'});
|
||||
apiKey = apiKey.replace(/\n$/, "");
|
||||
var apiVersion = 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue