mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
Fix new URL parameter being append after the '#' in CombodoGlobalToolbox.AddParameterToUrl
This commit is contained in:
17
js/utils.js
17
js/utils.js
@@ -713,19 +713,20 @@ const CombodoGlobalToolbox = {
|
|||||||
* @param sUrl {string} The URL to append the new param to
|
* @param sUrl {string} The URL to append the new param to
|
||||||
* @param sParamName {string} Name of the parameter
|
* @param sParamName {string} Name of the parameter
|
||||||
* @param sParamValue {string} Value of the param, needs to be already URL encoded
|
* @param sParamValue {string} Value of the param, needs to be already URL encoded
|
||||||
* @return {string} The sUrl parameters with the sParamName / sParamValue append at the right place
|
* @return {string} The sUrl parameter with the sParamName / sParamValue append at the end of the query string (but before the hash if any)
|
||||||
*/
|
*/
|
||||||
AddParameterToUrl: function(sUrl, sParamName, sParamValue)
|
AddParameterToUrl: function(sUrl, sParamName, sParamValue)
|
||||||
{
|
{
|
||||||
const bHasHash = sUrl.split('#')[1] !== undefined;
|
|
||||||
const bHasSomeParameters = sUrl.split('?')[1] !== undefined;
|
|
||||||
const sNewParamForUrl = sParamName + '=' + sParamValue;
|
const sNewParamForUrl = sParamName + '=' + sParamValue;
|
||||||
|
|
||||||
if (bHasHash || bHasSomeParameters) {
|
// Split URL around the '#'. Note that if there are multiple '#' in the URL (which is not permitted!) this method won't work.
|
||||||
sUrl += '&' + sNewParamForUrl;
|
const aHashParts = sUrl.split('#');
|
||||||
} else {
|
// Part of the URL starting from the protocol to the character before the '#' if one, to the end of the URL otherwise
|
||||||
sUrl += '?' + sNewParamForUrl;
|
const sPreHashPart = aHashParts[0];
|
||||||
}
|
// Part of the URL starting just after the '#' if one, null otherwise
|
||||||
|
const sPostHashPart = aHashParts[1] ?? null;
|
||||||
|
|
||||||
|
sUrl = sPreHashPart + (sUrl.split('?')[1] ? '&' : '?') + sNewParamForUrl + (sPostHashPart !== null ? '#' + sPostHashPart : '');
|
||||||
|
|
||||||
return sUrl;
|
return sUrl;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user