From b9f23fa20856b12a744d48148c72b27314d1095c Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Sat, 20 Aug 2011 18:51:43 +0100 Subject: [PATCH] handle bad changesets --- node/handler/PadMessageHandler.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/node/handler/PadMessageHandler.js b/node/handler/PadMessageHandler.js index 095d53485..5ae45a32b 100644 --- a/node/handler/PadMessageHandler.js +++ b/node/handler/PadMessageHandler.js @@ -382,12 +382,24 @@ function handleUserChanges(client, message) //ex. _checkChangesetAndPool //Copied from Etherpad, don't know what it does exactly - Changeset.checkRep(changeset); - Changeset.eachAttribNumber(changeset, function(n) { - if (! wireApool.getAttrib(n)) { - throw "Attribute pool is missing attribute "+n+" for changeset "+changeset; - } - }); + try + { + //this looks like a changeset check, it throws errors sometimes + Changeset.checkRep(changeset); + + Changeset.eachAttribNumber(changeset, function(n) { + if (! wireApool.getAttrib(n)) { + throw "Attribute pool is missing attribute "+n+" for changeset "+changeset; + } + }); + } + //there is an error in this changeset, so just refuse it + catch(e) + { + console.warn("Can't apply USER_CHANGES "+changeset+", cause it faild checkRep"); + client.json.send({disconnect:"badChangeset"}); + return; + } //ex. adoptChangesetAttribs