From 18f3ab169dd7429e1f46821abc91567dc25c001d Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Thu, 23 Nov 2023 11:20:41 +0000 Subject: [PATCH] fix: Improved autofilling network protocol prefix logic for rich link popup --- .../components/cell/RichText/LinkOptions.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/nc-gui/components/cell/RichText/LinkOptions.vue b/packages/nc-gui/components/cell/RichText/LinkOptions.vue index 90f40b52dc..eb677972a3 100644 --- a/packages/nc-gui/components/cell/RichText/LinkOptions.vue +++ b/packages/nc-gui/components/cell/RichText/LinkOptions.vue @@ -58,10 +58,23 @@ const checkLinkMark = (editor: Editor) => { return showLinkOptions } +function notStartingWithNetworkProtocol(inputString: string) { + const pattern = /^(?![^:]+:\/\/).*/ + + const isMatch = pattern.test(inputString) + + return isMatch +} + const onChange = () => { const isLinkMarkedStoredInEditor = editor.value.state?.storedMarks?.some((mark: Mark) => mark.type.name === 'link') let formatedHref = href.value - if (isValidURL(href.value) && href.value.length > 0 && !href.value.startsWith('/') && !href.value.startsWith('http')) { + if ( + isValidURL(href.value) && + href.value.length > 0 && + !href.value.startsWith('/') && + notStartingWithNetworkProtocol(href.value) + ) { formatedHref = `https://${href.value}` }