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

@@ -10,10 +10,10 @@ import { parser } from "@server/editor";
* @returns An array of document identifiers
*/
export default function parseDocumentIds(text: string): string[] {
const value = parser.parse(text);
const doc = parser.parse(text);
const identifiers: string[] = [];
function findLinks(node: Node) {
doc.descendants((node: Node) => {
// get text nodes
if (node.type.name === "text") {
// get marks for text nodes
@@ -28,15 +28,12 @@ export default function parseDocumentIds(text: string): string[] {
}
}
});
return false;
}
if (!node.content.size) {
return;
}
return true;
});
node.content.descendants(findLinks);
}
findLinks(value);
return identifiers;
}