From 097f2623c63eeab475c060504e90a21ce40fd6f4 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 22 Mar 2021 20:23:59 -0400 Subject: [PATCH] Changeset: Add sanity checks to `slicerZipperFunc()` --- src/static/js/Changeset.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index b15c35f69..50277e023 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -1185,6 +1185,17 @@ const slicerZipperFunc = (attOp, csOp, pool) => { copyOp(csOp, opOut); csOp.opcode = ''; } else { + for (const op of [attOp, csOp]) { + assert(op.chars >= op.lines, `op has more newlines than chars: ${op.toString()}`); + } + assert( + attOp.chars < csOp.chars ? attOp.lines <= csOp.lines + : attOp.chars > csOp.chars ? attOp.lines >= csOp.lines + : attOp.lines === csOp.lines, + 'line count mismatch when composing changesets A*B; ' + + `opA: ${attOp.toString()} opB: ${csOp.toString()}`); + assert(['+', '='].includes(attOp.opcode), `unexpected opcode in op: ${attOp.toString()}`); + assert(['-', '='].includes(csOp.opcode), `unexpected opcode in op: ${csOp.toString()}`); opOut.opcode = { '+': { '-': '', // The '-' cancels out (some of) the '+', leaving any remainder for the next call.