From 1e9d52304633eed8ad97a1764f4a19cbc6c2b9ed Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Fri, 16 Sep 2016 15:48:28 +0200 Subject: Return '' instead of 'null' This commit changes the behavior of getURLParameter(name) to return an empty string when the parameter is not set or has empty value. Before it returned 'null' as string. --- core/js/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/js/js.js b/core/js/js.js index c7a06b85e53..0a83f1104aa 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1723,7 +1723,7 @@ function formatDate(timestamp){ */ function getURLParameter(name) { return decodeURI( - (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1] + (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, ''])[1] ); } -- cgit v1.2.3 From c80c5ad9588ff71e92bfa43e6089e671f9ec8039 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Fri, 16 Sep 2016 16:03:15 +0200 Subject: Fixup getURLParameter behavior This commit further changes the behavior of getURLParmeter to handle encoded parameter values and returns the decoded string and improves behavior for parameters without value and multiple equals and other similar cases which did not work before. See the comments at http://stackoverflow.com/questions/1403888/get-escaped-url-parameter for a list of the issues handled by the updated implementation. This change does not change the general behavior of the function. Empty or non existing parameters still return an empty string (''). --- core/js/js.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/js/js.js b/core/js/js.js index 0a83f1104aa..67487ec979c 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1722,9 +1722,10 @@ function formatDate(timestamp){ * @return {string} */ function getURLParameter(name) { - return decodeURI( - (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, ''])[1] - ); + return decodeURIComponent( + (new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec( + location.search)||[,''])[1].replace(/\+/g, '%20') + )||''; } /** -- cgit v1.2.3