Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 056c7c8

Browse files
authored
Prevent infinite loops by dropping the input instead of crashing browser (#7632)
1 parent b7099f8 commit 056c7c8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/editor/model.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,6 @@ export default class EditorModel {
352352
* @param {Object} pos
353353
* @param {string} str
354354
* @param {string} inputType the source of the input, see html InputEvent.inputType
355-
* @param {bool} options.validate Whether characters will be validated by the part.
356-
* Validating allows the inserted text to be parsed according to the part rules.
357355
* @return {Number} how far from position (in characters) the insertion ended.
358356
* This can be more than the length of `str` when crossing non-editable parts, which are skipped.
359357
*/
@@ -384,7 +382,13 @@ export default class EditorModel {
384382
}
385383
while (str) {
386384
const newPart = this._partCreator.createPartForInput(str, index, inputType);
385+
const oldStr = str;
387386
str = newPart.appendUntilRejected(str, inputType);
387+
if (str === oldStr) {
388+
// nothing changed, break out of this infinite loop and log an error
389+
console.error(`Failed to update model for input (str ${str}) (type ${inputType})`);
390+
break;
391+
}
388392
this.insertPart(index, newPart);
389393
index += 1;
390394
}

0 commit comments

Comments
 (0)