Skip to content

Commit

Permalink
enhanced the getGraphiteURLKey function to escape(replace) additional…
Browse files Browse the repository at this point in the history
… characters

the were causing me issues on nasty urls.

The characters are:

* pipe (|)
* comma (,)
* plus (+)

See also here:
#651 (comment)
  • Loading branch information
EikeDawid committed Jun 5, 2015
1 parent 679ecf1 commit 9f2aa77
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ module.exports = {
pathName = 'slash';
}

var replace = ['.', '~', ' ', '/'];
var replace = ['.', '~', ' ', '/', '+', '%7C', ','];
replace.forEach(function(replaceMe) {
if (pathName.indexOf(replaceMe) > -1) {
pathName = pathName.split(replaceMe).join(char);
Expand Down
21 changes: 20 additions & 1 deletion test/util/utilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,26 @@ describe('util', function() {
var result = util.getGraphiteURLKey('http://www.sitespeed.io/image.gif');
assert.deepEqual(result,'http.www_sitespeed_io._image_gif');
});


it('Should escape pipes that make graphite data retrieval problematic', function() {
var result = util.getGraphiteURLKey('http://www.example.com/browse|ID|4.html');
assert.deepEqual(result,'http.www_example_com._browse_ID_4_html');
});

it('Should escape encoded pipe characters that make graphite data retrieval problematic', function() {
var result = util.getGraphiteURLKey('http://www.example.com/browse%7CID%7C4.html');
assert.deepEqual(result,'http.www_example_com._browse_ID_4_html');
});

it('Should escape "+" that make graphite data retrieval problematic', function() {
var result = util.getGraphiteURLKey('http://www.example.com/browse/hello+world');
assert.deepEqual(result,'http.www_example_com._browse_hello_world');
});

it('Should escape "," (comma) that makes graphite functions fail', function() {
var result = util.getGraphiteURLKey('http://www.example.com/browse/hello,world');
assert.deepEqual(result,'http.www_example_com._browse_hello_world');
});

});
});

0 comments on commit 9f2aa77

Please sign in to comment.