Restrict valid page names
parent
59ff0643b0
commit
04d6de18e6
|
@ -1,4 +1,4 @@
|
||||||
export function isValidPageName(name: string): boolean {
|
export function isValidPageName(name: string): boolean {
|
||||||
// Page can not be empty and not end with a file extension (e.g. "bla.md")
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ export async function renamePage(cmdDef: any) {
|
||||||
|
|
||||||
if (!isValidPageName(newName)) {
|
if (!isValidPageName(newName)) {
|
||||||
return editor.flashNotification(
|
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",
|
"error",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,8 +394,8 @@ export function renderMarkdownToHtml(
|
||||||
t.attrs!.src = options.translateUrls!(t.attrs!.src!);
|
t.attrs!.src = options.translateUrls!(t.attrs!.src!);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.name === "a") {
|
if (t.name === "a" && t.attrs!.href) {
|
||||||
t.attrs!.href = options.translateUrls!(t.attrs!.href!);
|
t.attrs!.href = options.translateUrls!(t.attrs!.href);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1167,7 +1167,7 @@ export class Editor {
|
||||||
|
|
||||||
if (!isValidPageName(name)) {
|
if (!isValidPageName(name)) {
|
||||||
return this.flashNotification(
|
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",
|
"error",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue