Skip to content

Build your personal knowledge base with Trilium Notes

fix(ckeditor5): avoid polynomial backtracking in the message slugifier

Elian Doran65c02cabc1da
diff --git a/packages/ckeditor5/src/messages.ts b/packages/ckeditor5/src/messages.ts
index 9e7a054cb8..8ad6c645ec 100644
--- a/packages/ckeditor5/src/messages.ts
+++ b/packages/ckeditor5/src/messages.ts
@@ -35,7 +35,9 @@ export function slugify(message: string): string {
return message
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
- .replace(/^-+|-+$/g, "");
+ // The collapse above leaves at most one dash at each end, so trimming a single one is
+ // enough — and matching `-+$` instead would rescan the whole string from every position.
+ .replace(/^-|-$/g, "");
}
/**