enhanced the getGraphiteURLKey function to escape(replace) additional characters

the were causing me issues on nasty urls.

The characters are:

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

See also here:
https://github.com/sitespeedio/sitespeed.io/issues/651#issuecomment-108979501
This commit is contained in:
Eike Dawid 2015-06-05 14:34:52 +01:00
parent 679ecf1467
commit 9f2aa77fa8
2 changed files with 21 additions and 2 deletions

View File

@ -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);

View File

@ -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');
});
});
});