Skip to content

Commit 86959f7

Browse files
committed
Changeset: Throw on unexpected chars while iterating ops
1 parent 657492e commit 86959f7

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/static/js/Changeset.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,21 @@ exports.newLen = (cs) => exports.unpack(cs).newLen;
197197
* @returns {OpIter} Operator iterator object.
198198
*/
199199
exports.opIterator = (opsStr) => {
200-
const regex = /((?:\*[0-9a-z]+)*)(?:\|([0-9a-z]+))?([-+=])([0-9a-z]+)|\?|/g;
200+
const regex = /((?:\*[0-9a-z]+)*)(?:\|([0-9a-z]+))?([-+=])([0-9a-z]+)|(.)/g;
201201

202202
const nextRegexMatch = () => {
203203
const result = regex.exec(opsStr);
204-
if (result[0] === '?') {
205-
error('Hit error opcode in op stream');
206-
}
207-
204+
if (!result) return null;
205+
if (result[5] === '$') return null; // Start of the insert operation character bank.
206+
if (result[5] != null) error(`invalid operation: ${opsStr.slice(regex.lastIndex - 1)}`);
208207
return result;
209208
};
210209
let regexResult = nextRegexMatch();
211210

211+
const hasNext = () => regexResult && !!regexResult[0];
212+
212213
const next = (op = new Op()) => {
213-
if (regexResult[0]) {
214+
if (hasNext()) {
214215
op.attribs = regexResult[1];
215216
op.lines = exports.parseNum(regexResult[2] || '0');
216217
op.opcode = regexResult[3];
@@ -222,8 +223,6 @@ exports.opIterator = (opsStr) => {
222223
return op;
223224
};
224225

225-
const hasNext = () => !!(regexResult[0]);
226-
227226
return {
228227
next,
229228
hasNext,

0 commit comments

Comments
 (0)