From c4442a3a5d617ae8fc68c9cfccf13b9b4767f283 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Thu, 26 Feb 2026 16:28:39 +0530 Subject: [PATCH] fix: don't replace # in web link fragments for attachment links --- frappe/public/js/frappe/form/sidebar/attachments.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/form/sidebar/attachments.js b/frappe/public/js/frappe/form/sidebar/attachments.js index bb36a2f65b..894856dcec 100644 --- a/frappe/public/js/frappe/form/sidebar/attachments.js +++ b/frappe/public/js/frappe/form/sidebar/attachments.js @@ -180,8 +180,18 @@ frappe.ui.form.Attachments = class Attachments { file_url = "/files/" + attachment.file_name; } } + + const is_web_url = /^(https?:)?\/\//i.test(file_url); + + file_url = encodeURI(file_url); + // hash is not escaped, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI - return encodeURI(file_url).replace(/#/g, "%23"); + // only encode hash if it's a local file path, not a web URL + if (!is_web_url) { + file_url = file_url.replace(/#/g, "%23"); + } + + return file_url; } get_file_id_from_file_url(file_url) { var fid;