mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
Changeset: Throw on unexpected chars while iterating ops
This commit is contained in:
parent
657492e191
commit
86959f7ebc
1 changed files with 7 additions and 8 deletions
|
@ -197,20 +197,21 @@ exports.newLen = (cs) => exports.unpack(cs).newLen;
|
||||||
* @returns {OpIter} Operator iterator object.
|
* @returns {OpIter} Operator iterator object.
|
||||||
*/
|
*/
|
||||||
exports.opIterator = (opsStr) => {
|
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 nextRegexMatch = () => {
|
||||||
const result = regex.exec(opsStr);
|
const result = regex.exec(opsStr);
|
||||||
if (result[0] === '?') {
|
if (!result) return null;
|
||||||
error('Hit error opcode in op stream');
|
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;
|
return result;
|
||||||
};
|
};
|
||||||
let regexResult = nextRegexMatch();
|
let regexResult = nextRegexMatch();
|
||||||
|
|
||||||
|
const hasNext = () => regexResult && !!regexResult[0];
|
||||||
|
|
||||||
const next = (op = new Op()) => {
|
const next = (op = new Op()) => {
|
||||||
if (regexResult[0]) {
|
if (hasNext()) {
|
||||||
op.attribs = regexResult[1];
|
op.attribs = regexResult[1];
|
||||||
op.lines = exports.parseNum(regexResult[2] || '0');
|
op.lines = exports.parseNum(regexResult[2] || '0');
|
||||||
op.opcode = regexResult[3];
|
op.opcode = regexResult[3];
|
||||||
|
@ -222,8 +223,6 @@ exports.opIterator = (opsStr) => {
|
||||||
return op;
|
return op;
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasNext = () => !!(regexResult[0]);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
next,
|
next,
|
||||||
hasNext,
|
hasNext,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue