From 01b0477b2773173810acfb4dd6808c156b7fea33 Mon Sep 17 00:00:00 2001 From: john gravois Date: Wed, 25 Mar 2015 09:51:59 -0700 Subject: [PATCH] fix cleanUrl regex so that spaces in folder names arent trimmed better regex --- spec/UtilSpec.js | 5 +++++ src/Util.js | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) 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] !== '/'){