diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 6c4708f08..35c76b5d9 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -1082,6 +1082,9 @@ const handleChangesetRequest = async (socket, {data: {granularity, start, reques const end = start + (100 * granularity); const {padId, author: authorId} = sessioninfos[socket.id]; const pad = await padManager.getPad(padId, null, authorId); + const headRev = pad.getHeadRevisionNumber(); + if (start > headRev) + start = headRev; const data = await getChangesetInfo(pad, start, end, granularity); data.requestID = requestID; socket.json.send({type: 'CHANGESET_REQ', data}); diff --git a/src/tests/backend/specs/messages.js b/src/tests/backend/specs/messages.js index f362d58b0..643005f12 100644 --- a/src/tests/backend/specs/messages.js +++ b/src/tests/backend/specs/messages.js @@ -133,6 +133,33 @@ describe(__filename, function () { await otherPad.remove(); } }); + + it('CHANGESET_REQ: revNum 2 is converted to head rev 1 (regression)', async function () { + const otherPadId = `${padId}other`; + assert(!await padManager.doesPadExist(otherPadId)); + const otherPad = await padManager.getPad(otherPadId, 'other text\n'); + try { + await otherPad.setText('other text\n'); + const resP = common.waitForSocketEvent(roSocket, 'message'); + await common.sendMessage(roSocket, { + component: 'pad', + padId: otherPadId, // The server should ignore this. + type: 'CHANGESET_REQ', + data: { + granularity: 1, + start: '2', + requestID: 'requestId', + }, + }); + const res = await resP; + assert.equal(res.type, 'CHANGESET_REQ'); + assert.equal(res.data.requestID, 'requestId'); + assert.equal(res.data.start, 1); + } + finally { + await otherPad.remove(); + } + }); }); describe('USER_CHANGES', function () {