2018-09-20 15:03:33 +02:00
|
|
|
const url = require('url');
|
2017-12-14 21:25:51 +01:00
|
|
|
|
2018-09-20 15:03:33 +02:00
|
|
|
const _private = {};
|
2017-12-13 22:06:31 +01:00
|
|
|
|
2018-09-20 15:03:33 +02:00
|
|
|
_private.removeDoubleCharacters = (character, string) => {
|
|
|
|
const stringArray = string.split('');
|
2016-08-23 13:47:59 +02:00
|
|
|
|
2018-09-20 15:03:33 +02:00
|
|
|
return stringArray.reduce((newString, currentCharacter, index) => {
|
2016-08-23 13:47:59 +02:00
|
|
|
if (
|
|
|
|
currentCharacter === character &&
|
|
|
|
stringArray[index + 1] === character
|
|
|
|
) {
|
|
|
|
return newString;
|
|
|
|
}
|
|
|
|
|
2018-09-20 15:03:33 +02:00
|
|
|
return `${newString}${currentCharacter}`;
|
2016-08-23 13:47:59 +02:00
|
|
|
}, '');
|
2017-12-13 22:06:31 +01:00
|
|
|
};
|
2016-08-23 13:47:59 +02:00
|
|
|
|
2017-12-13 22:06:31 +01:00
|
|
|
module.exports.removeOpenRedirectFromUrl = function removeOpenRedirectFromUrl(urlString) {
|
2018-09-20 15:03:33 +02:00
|
|
|
const parsedUrl = url.parse(urlString);
|
2016-08-23 13:47:59 +02:00
|
|
|
|
|
|
|
return (
|
2017-11-01 13:44:54 +00:00
|
|
|
// http://
|
|
|
|
(parsedUrl.protocol ? parsedUrl.protocol + '//' : '') +
|
2016-08-23 13:47:59 +02:00
|
|
|
(parsedUrl.auth || '') +
|
|
|
|
(parsedUrl.host || '') +
|
2017-12-13 22:06:31 +01:00
|
|
|
_private.removeDoubleCharacters('/', parsedUrl.path) +
|
2016-08-23 13:47:59 +02:00
|
|
|
(parsedUrl.hash || '')
|
|
|
|
);
|
2017-12-13 22:06:31 +01:00
|
|
|
};
|