diff --git a/src/definitions/behaviors/api.js b/src/definitions/behaviors/api.js index 273b95ef5..3234e574f 100644 --- a/src/definitions/behaviors/api.js +++ b/src/definitions/behaviors/api.js @@ -352,7 +352,7 @@ $.api = $.fn.api = function(parameters) { } else { module.verbose('Found required variable', variable, value); - url = url.replace(templatedString, value); + url = url.replace(templatedString, module.get.urlEncodedValue(value)); } }); } @@ -686,6 +686,19 @@ $.api = $.fn.api = function(parameters) { : settings ; }, + urlEncodedValue: function(value) { + var + decodedValue = window.decodeURIComponent(value), + encodedValue = window.encodeURIComponent(value), + alreadyEncoded = (decodedValue !== value) + ; + if(alreadyEncoded) { + module.debug('URL value is already encoded, avoiding double encoding', value); + return value; + } + module.verbose('Encoding value for url', value, encodedValue); + return encodedValue; + }, defaultData: function() { var data = {}