From 9eec0471f725c8a943125e3061ba40e4a815aa1b Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 21 Feb 2015 12:42:40 +0100 Subject: [PATCH] Fixed some URL issues in AJAX requests --- wcfsetup/install/files/js/WCF.js | 34 ++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 1d74052fe3..17857954e9 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -754,6 +754,32 @@ $.extend(WCF, { } return new Blob($byteArrays, { type: contentType }); + }, + + /** + * Converts legacy URLs to the URL schema used by WCF 2.1. + * + * @param string url + * @return string + */ + convertLegacyURL: function(url) { + if (URL_LEGACY_MODE) { + return url; + } + + return url.replace(/^index\.php\/(.*?)\/\?/, function(match, controller) { + var $parts = controller.split(/([A-Z][a-z0-9]+)/); + var $controller = ''; + for (var $i = 0, $length = $parts.length; $i < $length; $i++) { + var $part = $parts[$i].trim(); + if ($part.length) { + if ($controller.length) $controller += '-'; + $controller += $part.toLowerCase(); + } + } + + return 'index.php?' + $controller + '/&'; + }); } }); @@ -2533,9 +2559,7 @@ WCF.Action.Proxy = Class.extend({ autoAbortPrevious: false }, options); - if (!URL_LEGACY_MODE) { - this.options.url = this.options.url.replace(/^index\.php\/(.*?)\/\?/, '?$1/&'); - } + this.options.url = WCF.convertLegacyURL(this.options.url); this.confirmationDialog = null; this.loading = null; @@ -8927,9 +8951,7 @@ WCF.Upload = Class.extend({ url: 'index.php/AJAXUpload/?t=' + SECURITY_TOKEN + SID_ARG_2ND }, options || { }); - if (!URL_LEGACY_MODE) { - this._options.url = this._options.url.replace(/^index\.php\/(.*?)\/\?/, '?$1/&'); - } + this._options.url = WCF.convertLegacyURL(this._options.url); // check for ajax upload support var $xhr = new XMLHttpRequest(); -- 2.20.1