mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 18:25:49 +03:00
Prevent infinite loops by dropping the input instead of crashing browser (#7632)
This commit is contained in:
parent
b7099f84c3
commit
056c7c8d65
1 changed files with 6 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue