From 9f2aa77fa83a61f01fded69b98025ceb199480a6 Mon Sep 17 00:00:00 2001 From: Eike Dawid Date: Fri, 5 Jun 2015 14:34:52 +0100 Subject: [PATCH] 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 --- lib/util/util.js | 2 +- test/util/utilTest.js | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/util/util.js b/lib/util/util.js index f5bcabf913..d2087956f2 100644 --- a/lib/util/util.js +++ b/lib/util/util.js @@ -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); diff --git a/test/util/utilTest.js b/test/util/utilTest.js index 0f1b39f251..b84510a096 100644 --- a/test/util/utilTest.js +++ b/test/util/utilTest.js @@ -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'); + }); }); });