From 3bc566915eefbbdc743883b154144b37b5771bf9 Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Tue, 20 May 2025 07:32:07 -0400 Subject: [PATCH] Fix document URL generation for titles with only special characters (#9258) * Fix document URL generation for titles with only special characters * Refactor: Update instance path method to use static getPath method --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> --- server/models/Document.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/models/Document.ts b/server/models/Document.ts index ae9f4df6c1..915f14bb69 100644 --- a/server/models/Document.ts +++ b/server/models/Document.ts @@ -383,11 +383,10 @@ class Document extends ArchivableModel< /** The frontend path to this document. */ get path() { - if (!this.title) { - return `/doc/untitled-${this.urlId}`; - } - const slugifiedTitle = slugify(this.title); - return `/doc/${slugifiedTitle}-${this.urlId}`; + return Document.getPath({ + title: this.title, + urlId: this.urlId, + }); } get tasks() { @@ -400,7 +399,13 @@ class Document extends ArchivableModel< if (!title.length) { return `/doc/untitled-${urlId}`; } - return `/doc/${slugify(title)}-${urlId}`; + const slugifiedTitle = slugify(title); + // If the slugified title is empty (e.g., title only had special characters), + // use "untitled" as a fallback to prevent empty URL segments + if (!slugifiedTitle) { + return `/doc/untitled-${urlId}`; + } + return `/doc/${slugifiedTitle}-${urlId}`; } // hooks @@ -867,6 +872,7 @@ class Document extends ArchivableModel< /** * Find all of the child documents for this document * + * @param where Omit, "parentDocumentId"> * @param options FindOptions * @returns A promise that resolve to a list of documents */