From 2ad1e1d533540d1f387143d62459bf97c8c382e5 Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 25 Oct 2025 22:44:59 +0800 Subject: [PATCH] ui: preview: escape brackets in link --- packages/ui-default/components/preview/preview.page.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/ui-default/components/preview/preview.page.ts b/packages/ui-default/components/preview/preview.page.ts index a67361e54..223a02476 100644 --- a/packages/ui-default/components/preview/preview.page.ts +++ b/packages/ui-default/components/preview/preview.page.ts @@ -46,10 +46,12 @@ const dialogAction = (id) => [ ]; function bindCopyLink(id, src: string) { + // Usually brackets are allowed in URLs, but in markdown there's need to escape them + src = src.replace(/\(/g, '%28').replace(/\)/g, '%29'); const url = !['file', 'files'].some((i) => window.location.href.endsWith(i)) || ['homework', 'training'].some((i) => window.location.href.match(`${i}/.*/file`)) ? `file://${src.substring(src.lastIndexOf('/') + 1)}` : src; - const clip = new Clipboard(`#copy-${id}`, { text: () => `${url}` }); + const clip = new Clipboard(`#copy-${id}`, { text: () => url }); clip.on('success', () => Notification.success(i18n(`${url.startsWith('file://') ? 'Reference' : 'Download'} link copied to clipboard!`))); clip.on('error', () => Notification.error(i18n('Copy failed :('))); } @@ -142,11 +144,7 @@ export async function previewFile(ev?, type = '') { const id = nanoid(); const dialog = new ActionDialog({ $body: tpl.typoMsg(i18n('Cannot preview this file. Download now?')), - $action: [ - tpl``, - tpl``, - tpl``, - ], + $action: dialogAction(id), }); bindCopyLink(id, link); const action = await dialog.open();