From 056c7c8d655eaa18db87c0ebef6ee94cfdc28c1c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 26 Jan 2022 10:16:01 +0000 Subject: [PATCH] Prevent infinite loops by dropping the input instead of crashing browser (#7632) --- src/editor/model.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/editor/model.ts b/src/editor/model.ts index b9850a7ba7..59c7691d89 100644 --- a/src/editor/model.ts +++ b/src/editor/model.ts @@ -352,8 +352,6 @@ export default class EditorModel { * @param {Object} pos * @param {string} str * @param {string} inputType the source of the input, see html InputEvent.inputType - * @param {bool} options.validate Whether characters will be validated by the part. - * Validating allows the inserted text to be parsed according to the part rules. * @return {Number} how far from position (in characters) the insertion ended. * This can be more than the length of `str` when crossing non-editable parts, which are skipped. */ @@ -384,7 +382,13 @@ export default class EditorModel { } while (str) { const newPart = this._partCreator.createPartForInput(str, index, inputType); + const oldStr = str; str = newPart.appendUntilRejected(str, inputType); + if (str === oldStr) { + // nothing changed, break out of this infinite loop and log an error + console.error(`Failed to update model for input (str ${str}) (type ${inputType})`); + break; + } this.insertPart(index, newPart); index += 1; }