2017-12-13 16:06:31 -05:00
|
|
|
'use strict';
|
2016-08-23 06:47:59 -05:00
|
|
|
|
2017-12-13 16:06:31 -05:00
|
|
|
const url = require('url');
|
|
|
|
let _private = {};
|
|
|
|
|
|
|
|
_private.removeDoubleCharacters = function removeDoubleCharacters(character, string) {
|
|
|
|
let stringArray = string.split('');
|
2016-08-23 06:47:59 -05:00
|
|
|
|
|
|
|
return stringArray.reduce(function (newString, currentCharacter, index) {
|
|
|
|
if (
|
|
|
|
currentCharacter === character &&
|
|
|
|
stringArray[index + 1] === character
|
|
|
|
) {
|
|
|
|
return newString;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newString + currentCharacter;
|
|
|
|
}, '');
|
2017-12-13 16:06:31 -05:00
|
|
|
};
|
2016-08-23 06:47:59 -05:00
|
|
|
|
2017-12-13 16:06:31 -05:00
|
|
|
module.exports.removeOpenRedirectFromUrl = function removeOpenRedirectFromUrl(urlString) {
|
|
|
|
let parsedUrl = url.parse(urlString);
|
2016-08-23 06:47:59 -05:00
|
|
|
|
|
|
|
return (
|
2017-11-01 08:44:54 -05:00
|
|
|
// http://
|
|
|
|
(parsedUrl.protocol ? parsedUrl.protocol + '//' : '') +
|
2016-08-23 06:47:59 -05:00
|
|
|
(parsedUrl.auth || '') +
|
|
|
|
(parsedUrl.host || '') +
|
2017-12-13 16:06:31 -05:00
|
|
|
_private.removeDoubleCharacters('/', parsedUrl.path) +
|
2016-08-23 06:47:59 -05:00
|
|
|
(parsedUrl.hash || '')
|
|
|
|
);
|
2017-12-13 16:06:31 -05:00
|
|
|
};
|