From 9c17b03660fba65a118ebc71f8fdbd001985e8a7 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 3 Oct 2021 04:47:29 -0400 Subject: [PATCH] Changeset: Require Op opcode and attribs to be strings --- src/static/js/Changeset.js | 6 ++++-- src/static/js/contentcollector.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index 85ee35700..426835915 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -488,9 +488,11 @@ exports.opAssembler = () => { * @param {Op} op - Operation to add. Ownership remains with the caller. */ const append = (op) => { - if (op.attribs != null) serialized += op.attribs; + if (!op.opcode) throw new TypeError('null op'); + if (typeof op.attribs !== 'string') throw new TypeError('attribs must be a string'); + serialized += op.attribs; if (op.lines) serialized += `|${exports.numToString(op.lines)}`; - if (op.opcode != null) serialized += op.opcode; + serialized += op.opcode; serialized += exports.numToString(op.chars); }; diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index 3d2bd9aa8..54c628804 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -92,7 +92,7 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author) attribsBuilder = Changeset.smartOpAssembler(); }, textOfLine: (i) => textArray[i], - appendText: (txt, attrString) => { + appendText: (txt, attrString = '') => { textArray[textArray.length - 1] += txt; op.attribs = attrString; op.chars = txt.length;