A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
editor: encode url before validating and saving in link popup (#10568)
Kashaf Ansaric3a15b4f5f30
diff --git a/packages/editor/src/toolbar/popups/link-popup.tsx b/packages/editor/src/toolbar/popups/link-popup.tsxindex 915de7016..deff14209 100644--- a/packages/editor/src/toolbar/popups/link-popup.tsx+++ b/packages/editor/src/toolbar/popups/link-popup.tsx@@ -29,7 +29,6 @@ import { findMark, selectionToOffset } from "../../utils/prosemirror.js";import { Editor, getMarkAttributes } from "@tiptap/core";import { strings } from "@notesnook/intl";import { useState } from "react";-import { test } from "linkifyjs";export type LinkPopupProps = {link?: LinkDefinition;@@ -51,11 +50,22 @@ export function LinkPopup(props: LinkPopupProps) {const handleDone = () => {const href = link.current?.href?.trim();- if (!href || (!isInternalLink(href) && !test(href))) {+ if (!href) {setError(strings.enterValidUrl());return;}- onDone(link.current);++ if (isInternalLink(href)) {+ onDone(link.current);+ return;+ }++ try {+ const url = new URL(href);+ onDone({ ...link.current, href: url.href });+ } catch {+ setError(strings.enterValidUrl());+ }};return (@@ -116,7 +126,7 @@ export function LinkPopup(props: LinkPopupProps) {autoFocusplaceholder="https://example.com/"defaultValue={link.current?.href}- variant={error ? "error" : undefined}+ variant={error ? "error" : "input"}onChange={(e) => {if (error) setError(null);link.current = { ...link.current, href: e.target.value };