CRM.url - Encode url path if slashes in placeholder were also encoded
authorColeman Watts <coleman@civicrm.org>
Wed, 21 Apr 2021 20:06:54 +0000 (16:06 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 21 Apr 2021 21:30:12 +0000 (17:30 -0400)
js/crm.ajax.js

index b7ce1d9465b62db5bf04561ba5e338e67108b80d..aabfd28f3aaf6b55edaf3d9d651258039ee65b8f 100644 (file)
       mode = CRM.config && CRM.config.isFrontend ? 'front' : 'back';
     }
     query = query || '';
-    var frag = path.split('?');
-    var url = tplURL[mode].replace("civicrm/placeholder-url-path", frag[0]);
+    var url,
+      frag = path.split('?');
+    // Encode url path only if slashes in placeholder were also encoded
+    if (tplURL[mode].indexOf('civicrm/placeholder-url-path') >= 0) {
+      url = tplURL[mode].replace('civicrm/placeholder-url-path', frag[0]);
+    } else {
+      url = tplURL[mode].replace('civicrm%2Fplaceholder-url-path', encodeURIComponent(frag[0]));
+    }
 
-    if (!query) {
+    if (_.isEmpty(query)) {
       url = url.replace(/[?&]civicrm-placeholder-url-query=1/, '');
-    }
-    else {
-      url = url.replace("civicrm-placeholder-url-query=1", typeof query === 'string' ? query : $.param(query));
+    } else {
+      url = url.replace('civicrm-placeholder-url-query=1', typeof query === 'string' ? query : $.param(query));
     }
     if (frag[1]) {
       url += (url.indexOf('?') < 0 ? '?' : '&') + frag[1];