Prevent infinite loops by dropping the input instead of crashing browser (#7632)

This commit is contained in:
Michael Telatynski 2022-01-26 10:16:01 +00:00 committed by GitHub
parent b7099f84c3
commit 056c7c8d65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
}