Skip to content

Commit d7c5180

Browse files
committed
Changeset: Add sanity checks to slicerZipperFunc()
1 parent 9ece5d2 commit d7c5180

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/static/js/Changeset.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,17 @@ const slicerZipperFunc = (attOp, csOp, pool) => {
11851185
copyOp(csOp, opOut);
11861186
csOp.opcode = '';
11871187
} else {
1188+
for (const op of [attOp, csOp]) {
1189+
assert(op.chars >= op.lines, `op has more newlines than chars: ${op.toString()}`);
1190+
}
1191+
assert(
1192+
attOp.chars < csOp.chars ? attOp.lines <= csOp.lines
1193+
: attOp.chars > csOp.chars ? attOp.lines >= csOp.lines
1194+
: attOp.lines === csOp.lines,
1195+
'line count mismatch when composing changesets A*B; ' +
1196+
`opA: ${attOp.toString()} opB: ${csOp.toString()}`);
1197+
assert(['+', '='].includes(attOp.opcode), `unexpected opcode in op: ${attOp.toString()}`);
1198+
assert(['-', '='].includes(csOp.opcode), `unexpected opcode in op: ${csOp.toString()}`);
11881199
opOut.opcode = {
11891200
'+': {
11901201
'-': '', // The '-' cancels out (some of) the '+', leaving any remainder for the next call.

0 commit comments

Comments
 (0)