From 86959f7ebc25665c26c7b3dd28184bd9fccc99e2 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 21 Oct 2021 03:17:28 -0400 Subject: [PATCH] Changeset: Throw on unexpected chars while iterating ops --- src/static/js/Changeset.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index 0b3b01a7c..5d4871c5e 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -197,20 +197,21 @@ exports.newLen = (cs) => exports.unpack(cs).newLen; * @returns {OpIter} Operator iterator object. */ exports.opIterator = (opsStr) => { - const regex = /((?:\*[0-9a-z]+)*)(?:\|([0-9a-z]+))?([-+=])([0-9a-z]+)|\?|/g; + const regex = /((?:\*[0-9a-z]+)*)(?:\|([0-9a-z]+))?([-+=])([0-9a-z]+)|(.)/g; const nextRegexMatch = () => { const result = regex.exec(opsStr); - if (result[0] === '?') { - error('Hit error opcode in op stream'); - } - + if (!result) return null; + if (result[5] === '$') return null; // Start of the insert operation character bank. + if (result[5] != null) error(`invalid operation: ${opsStr.slice(regex.lastIndex - 1)}`); return result; }; let regexResult = nextRegexMatch(); + const hasNext = () => regexResult && !!regexResult[0]; + const next = (op = new Op()) => { - if (regexResult[0]) { + if (hasNext()) { op.attribs = regexResult[1]; op.lines = exports.parseNum(regexResult[2] || '0'); op.opcode = regexResult[3]; @@ -222,8 +223,6 @@ exports.opIterator = (opsStr) => { return op; }; - const hasNext = () => !!(regexResult[0]); - return { next, hasNext,