fix: Double recursive loops can cause server lockup on deeply nested docs (#5222)

This commit is contained in:
Tom Moor
2023-04-18 19:38:35 -04:00
committed by GitHub
parent bcffd81c9c
commit 1642eb610d
7 changed files with 61 additions and 27 deletions

View File

@@ -49,22 +49,21 @@ export default class ProsemirrorHelper {
static parseMentions(node: Node) {
const mentions: MentionAttrs[] = [];
function findMentions(node: Node) {
node.descendants((node: Node) => {
if (
node.type.name === "mention" &&
!mentions.some((m) => m.id === node.attrs.id)
) {
mentions.push(node.attrs as MentionAttrs);
return false;
}
if (!node.content.size) {
return;
return false;
}
node.content.descendants(findMentions);
}
findMentions(node);
return true;
});
return mentions;
}