mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 04:43:12 +03:00
1a4506dcf0
- These two functions have no dependencies and are only used in valiation/upload - Co-locating the code makes it easier to move - Exported them with a new module.exports._test pattern - we'll see about whether this is a good idea - This is one of many similar changes needed to make it easier to refactor to the existing setup
32 lines
854 B
JavaScript
32 lines
854 B
JavaScript
const url = require('url');
|
|
|
|
const _private = {};
|
|
|
|
_private.removeDoubleCharacters = (character, string) => {
|
|
const stringArray = string.split('');
|
|
|
|
return stringArray.reduce((newString, currentCharacter, index) => {
|
|
if (
|
|
currentCharacter === character &&
|
|
stringArray[index + 1] === character
|
|
) {
|
|
return newString;
|
|
}
|
|
|
|
return `${newString}${currentCharacter}`;
|
|
}, '');
|
|
};
|
|
|
|
module.exports.removeOpenRedirectFromUrl = function removeOpenRedirectFromUrl(urlString) {
|
|
const parsedUrl = url.parse(urlString);
|
|
|
|
return (
|
|
// http://
|
|
(parsedUrl.protocol ? parsedUrl.protocol + '//' : '') +
|
|
(parsedUrl.auth || '') +
|
|
(parsedUrl.host || '') +
|
|
_private.removeDoubleCharacters('/', parsedUrl.path) +
|
|
(parsedUrl.hash || '')
|
|
);
|
|
};
|