Skip to content

Commit

Permalink
fix cleanUrl regex so that spaces in folder names arent trimmed
Browse files Browse the repository at this point in the history
better regex
  • Loading branch information
jgravois committed Mar 26, 2015
1 parent 24315aa commit 01b0477
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions spec/UtilSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] !== '/'){
Expand Down

0 comments on commit 01b0477

Please sign in to comment.