From 04d6de18e6685316511a4d7b7920c35e98c0617b Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Fri, 7 Jul 2023 11:44:05 +0200 Subject: [PATCH] Restrict valid page names --- plug-api/lib/page.ts | 2 +- plugs/core/page.ts | 2 +- plugs/markdown/markdown_render.ts | 4 ++-- web/editor.tsx | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plug-api/lib/page.ts b/plug-api/lib/page.ts index e90fe65b..1d1ac00e 100644 --- a/plug-api/lib/page.ts +++ b/plug-api/lib/page.ts @@ -1,4 +1,4 @@ export function isValidPageName(name: string): boolean { // Page can not be empty and not end with a file extension (e.g. "bla.md") - return name !== "" && !/\.[a-zA-Z]+$/.test(name); + return name !== "" && !name.startsWith(".") && !/\.[a-zA-Z]+$/.test(name); } diff --git a/plugs/core/page.ts b/plugs/core/page.ts index b6268f1a..846c158d 100644 --- a/plugs/core/page.ts +++ b/plugs/core/page.ts @@ -139,7 +139,7 @@ export async function renamePage(cmdDef: any) { if (!isValidPageName(newName)) { return editor.flashNotification( - "Invalid page name: page names cannot end with a file extension", + "Invalid page name: page names cannot end with a file extension nor start with a '.'", "error", ); } diff --git a/plugs/markdown/markdown_render.ts b/plugs/markdown/markdown_render.ts index e1efef82..0a177e9a 100644 --- a/plugs/markdown/markdown_render.ts +++ b/plugs/markdown/markdown_render.ts @@ -394,8 +394,8 @@ export function renderMarkdownToHtml( t.attrs!.src = options.translateUrls!(t.attrs!.src!); } - if (t.name === "a") { - t.attrs!.href = options.translateUrls!(t.attrs!.href!); + if (t.name === "a" && t.attrs!.href) { + t.attrs!.href = options.translateUrls!(t.attrs!.href); } }); } diff --git a/web/editor.tsx b/web/editor.tsx index dd4de055..dedc5e2c 100644 --- a/web/editor.tsx +++ b/web/editor.tsx @@ -1167,7 +1167,7 @@ export class Editor { if (!isValidPageName(name)) { return this.flashNotification( - "Invalid page name: page names cannot end with a file extension", + "Invalid page name: page names cannot end with a file extension nor start with a '.'", "error", ); }