Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix - fixed the Notion page URL validation bug

Ashraf00fa3c317286
diff --git a/components/documents/add-document-modal.tsx b/components/documents/add-document-modal.tsx
index 0ab231ac..ec46b7a7 100644
--- a/components/documents/add-document-modal.tsx
+++ b/components/documents/add-document-modal.tsx
@@ -19,6 +19,7 @@ import { Button } from "@/components/ui/button";
import { usePlausible } from "next-plausible";
import { toast } from "sonner";
import { useTeam } from "@/context/team-context";
+import { parsePageId } from "notion-utils";
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
@@ -178,12 +179,20 @@ export function AddDocumentModal({
event: FormEvent<HTMLFormElement>,
): Promise<void> => {
event.preventDefault();
+ const validateNotionPageURL = parsePageId(notionLink);
+ // Check if it's a valid URL or not by Regx
+ const isValidURL =
+ /^(https?:\/\/)?([a-zA-Z0-9-]+\.){1,}[a-zA-Z]{2,}([a-zA-Z0-9-._~:/?#[\]@!$&'()*+,;=]+)?$/;
- // Check if the file is chosen
+ // Check if the field is empty or not
if (!notionLink) {
toast.error("Please enter a Notion link to proceed.");
return; // prevent form from submitting
}
+ if (validateNotionPageURL === null || !isValidURL.test(notionLink)) {
+ toast.error("Please enter a valid Notion link to proceed.");
+ return;
+ }
try {
setUploading(true);