ensure targetRev is limited to headRev for CHANGESET_REQs

This commit is contained in:
webzwo0i 2023-06-25 23:33:15 +02:00
parent f4c3fd5a73
commit 6ae7b14051
2 changed files with 30 additions and 0 deletions

View file

@ -1082,6 +1082,9 @@ const handleChangesetRequest = async (socket, {data: {granularity, start, reques
const end = start + (100 * granularity); const end = start + (100 * granularity);
const {padId, author: authorId} = sessioninfos[socket.id]; const {padId, author: authorId} = sessioninfos[socket.id];
const pad = await padManager.getPad(padId, null, authorId); 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); const data = await getChangesetInfo(pad, start, end, granularity);
data.requestID = requestID; data.requestID = requestID;
socket.json.send({type: 'CHANGESET_REQ', data}); socket.json.send({type: 'CHANGESET_REQ', data});

View file

@ -133,6 +133,33 @@ describe(__filename, function () {
await otherPad.remove(); 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 () { describe('USER_CHANGES', function () {