From c98b97a21c71511bea497a60dd0bc42df894870d Mon Sep 17 00:00:00 2001 From: tundebabzy Date: Wed, 28 Jun 2017 10:08:15 +0100 Subject: [PATCH] Using " causes issues #7776 (#3563) * refactors `get_route_str`. The result is the addition of two new functions - `get_raw_route_str` and `_decode_str` * delays decoding of route parts --- frappe/public/js/frappe/router.js | 35 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/frappe/public/js/frappe/router.js b/frappe/public/js/frappe/router.js index 7a58076a60..c3cdc971aa 100644 --- a/frappe/public/js/frappe/router.js +++ b/frappe/public/js/frappe/router.js @@ -67,9 +67,10 @@ frappe.route = function() { frappe.get_route = function(route) { // for app - var route = frappe.get_route_str(route).split('/') + var route = frappe.get_raw_route_str(route).split('/'); + route = $.map(route, frappe._decode_str); var parts = route[route.length - 1].split("?"); - route[route.length - 1] = parts[0]; + route[route.length - 1] = frappe._decode_str(parts[0]); if (parts.length > 1) { var query_params = get_query_params(parts[1]); frappe.route_options = $.extend(frappe.route_options || {}, query_params); @@ -92,25 +93,31 @@ frappe.get_prev_route = function() { } } -frappe.get_route_str = function(route) { +frappe._decode_str = function(r) { + try { + return decodeURIComponent(r); + } catch(e) { + if (e instanceof URIError) { + return r; + } else { + throw e; + } + } +} + +frappe.get_raw_route_str = function(route) { if(!route) route = window.location.hash; if(route.substr(0,1)=='#') route = route.substr(1); if(route.substr(0,1)=='!') route = route.substr(1); - route = $.map(route.split('/'), function(r) { - try { - return decodeURIComponent(r); - } catch(e) { - if (e instanceof URIError) { - return r; - } else { - throw e; - } - } + return route; +} - }).join('/'); +frappe.get_route_str = function(route) { + var rawRoute = frappe.get_raw_route_str() + route = $.map(rawRoute.split('/'), frappe._decode_str).join('/'); return route; }