From eb4c4fb7b248ff58cd857ed8a2f809a33e7dfd6d Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 7 Sep 2022 21:25:51 +0530 Subject: [PATCH] fix: encode docname when routing (backport #17092) (#17374) (cherry picked from commit c8777c59cf665ab54218cd7bf9accd1d8e22ddf9) Co-authored-by: phot0n --- cypress/integration/table_multiselect.js | 2 +- frappe/public/js/frappe/list/list_view.js | 4 +--- frappe/public/js/frappe/router.js | 7 +------ 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/cypress/integration/table_multiselect.js b/cypress/integration/table_multiselect.js index 133af44d51..4f95b50147 100644 --- a/cypress/integration/table_multiselect.js +++ b/cypress/integration/table_multiselect.js @@ -52,6 +52,6 @@ context("Table MultiSelect", () => { "existing_value" ); cy.get("@existing_value").find(".btn-link-to-form").click(); - cy.location("pathname").should("contain", "/user/test@erpnext.com"); + cy.location("pathname").should("contain", "/user/test%40erpnext.com"); }); }); diff --git a/frappe/public/js/frappe/list/list_view.js b/frappe/public/js/frappe/list/list_view.js index c7a2a9b72c..032832b597 100644 --- a/frappe/public/js/frappe/list/list_view.js +++ b/frappe/public/js/frappe/list/list_view.js @@ -894,11 +894,9 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList { return this.settings.get_form_link(doc); } - const docname = cstr(doc.name).match(/[%'"#\s]/) ? encodeURIComponent(doc.name) : doc.name; - return `/app/${frappe.router.slug( frappe.router.doctype_layout || this.doctype - )}/${docname}`; + )}/${encodeURIComponent(cstr(doc.name))}`; } get_seen_class(doc) { diff --git a/frappe/public/js/frappe/router.js b/frappe/public/js/frappe/router.js index 6a0c745f29..0d1b815bce 100644 --- a/frappe/public/js/frappe/router.js +++ b/frappe/public/js/frappe/router.js @@ -369,12 +369,7 @@ frappe.router = { frappe.route_options = a; return null; } else { - a = String(a); - if (a && a.match(/[%'"#\s\t]/)) { - // if special chars, then encode - a = encodeURIComponent(a); - } - return a; + return encodeURIComponent(String(a)); } }).join("/"); let private_home = frappe.workspaces[`home-${frappe.user.name.toLowerCase()}`];