diff --git a/spec/UtilSpec.js b/spec/UtilSpec.js index c7fff001c..8183cab5f 100644 --- a/spec/UtilSpec.js +++ b/spec/UtilSpec.js @@ -44,6 +44,11 @@ describe('L.esri.Util', function () { expect(url).to.equal('http://arcgis.com/'); }); + it('shouldnt trim spaces in the middle', function(){ + var url = L.esri.Util.cleanUrl(' http://arcgis.com/cool folder/anotherfolder '); + expect(url).to.equal('http://arcgis.com/cool folder/anotherfolder/'); + }); + it('should convert a GeoJSON Point to an ArcGIS Point', function() { var input = { 'type': 'Point', diff --git a/src/Util.js b/src/Util.js index fba908368..bef900d02 100644 --- a/src/Util.js +++ b/src/Util.js @@ -386,9 +386,10 @@ return featureCollection; }; - // trim whitespace and add a tailing slash is needed to a url + // trim url whitespace and add a trailing slash if needed EsriLeaflet.Util.cleanUrl = function(url){ - url = url.replace(/\s\s*/g, ''); + //trim leading and trailing spaces, but not spaces inside the url + url = url.replace(/^\s+|\s+$|\A\s+|\s+\z/g, ''); //add a trailing slash to the url if the user omitted it if(url[url.length-1] !== '/'){