mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-08 03:02:03 +01:00
Merge pull request #2404 from webzwo0i/sanity-in-atext
block changeset if it deletes more lines than exist in the whole pad
This commit is contained in:
commit
7df944b3fd
2 changed files with 14 additions and 1 deletions
|
@ -742,7 +742,16 @@ function handleUserChanges(data, cb)
|
||||||
return callback(new Error("Can't apply USER_CHANGES "+changeset+" with oldLen " + Changeset.oldLen(changeset) + " to document of length " + prevText.length));
|
return callback(new Error("Can't apply USER_CHANGES "+changeset+" with oldLen " + Changeset.oldLen(changeset) + " to document of length " + prevText.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
pad.appendRevision(changeset, thisSession.author);
|
try
|
||||||
|
{
|
||||||
|
pad.appendRevision(changeset, thisSession.author);
|
||||||
|
}
|
||||||
|
catch(e)
|
||||||
|
{
|
||||||
|
client.json.send({disconnect:"badChangeset"});
|
||||||
|
stats.meter('failedChangesets').mark();
|
||||||
|
return callback(e)
|
||||||
|
}
|
||||||
|
|
||||||
var correctionChangeset = _correctMarkersInPad(pad.atext, pad.pool);
|
var correctionChangeset = _correctMarkersInPad(pad.atext, pad.pool);
|
||||||
if (correctionChangeset) {
|
if (correctionChangeset) {
|
||||||
|
|
|
@ -903,6 +903,8 @@ exports.pack = function (oldLen, newLen, opsStr, bank) {
|
||||||
* @params str {string} String to which a Changeset should be applied
|
* @params str {string} String to which a Changeset should be applied
|
||||||
*/
|
*/
|
||||||
exports.applyToText = function (cs, str) {
|
exports.applyToText = function (cs, str) {
|
||||||
|
var totalNrOfLines = str.split("\n").length;
|
||||||
|
var removedLines = 0;
|
||||||
var unpacked = exports.unpack(cs);
|
var unpacked = exports.unpack(cs);
|
||||||
exports.assert(str.length == unpacked.oldLen, "mismatched apply: ", str.length, " / ", unpacked.oldLen);
|
exports.assert(str.length == unpacked.oldLen, "mismatched apply: ", str.length, " / ", unpacked.oldLen);
|
||||||
var csIter = exports.opIterator(unpacked.ops);
|
var csIter = exports.opIterator(unpacked.ops);
|
||||||
|
@ -916,6 +918,7 @@ exports.applyToText = function (cs, str) {
|
||||||
assem.append(bankIter.take(op.chars));
|
assem.append(bankIter.take(op.chars));
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
|
removedLines += op.lines;
|
||||||
strIter.skip(op.chars);
|
strIter.skip(op.chars);
|
||||||
break;
|
break;
|
||||||
case '=':
|
case '=':
|
||||||
|
@ -923,6 +926,7 @@ exports.applyToText = function (cs, str) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exports.assert(totalNrOfLines >= removedLines,"cannot remove ", removedLines, " lines from text with ", totalNrOfLines, " lines");
|
||||||
assem.append(strIter.take(strIter.remaining()));
|
assem.append(strIter.take(strIter.remaining()));
|
||||||
return assem.toString();
|
return assem.toString();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue