0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Moved removeOpenRedirectFromUrl to local web utils

refs #9178

- see https://github.com/TryGhost/Ghost/issues/9178#issuecomment-351521897
This commit is contained in:
kirrg001 2017-12-13 22:06:31 +01:00
parent 485c264c69
commit 6e915e8e89
3 changed files with 13 additions and 16 deletions

View file

@ -132,7 +132,6 @@ utils = {
}, },
readCSV: require('./read-csv'), readCSV: require('./read-csv'),
removeOpenRedirectFromUrl: require('./remove-open-redirect-from-url'),
zipFolder: require('./zip-folder'), zipFolder: require('./zip-folder'),
generateAssetHash: require('./asset-hash'), generateAssetHash: require('./asset-hash'),
tokens: require('./tokens'), tokens: require('./tokens'),

View file

@ -14,7 +14,7 @@
var urlService = require('../../services/url'), var urlService = require('../../services/url'),
common = require('../../lib/common'), common = require('../../lib/common'),
globalUtils = require('../../utils'), localUtils = require('../utils'),
uncapitalise; uncapitalise;
uncapitalise = function uncapitalise(req, res, next) { uncapitalise = function uncapitalise(req, res, next) {
@ -46,10 +46,7 @@ uncapitalise = function uncapitalise(req, res, next) {
* That encoding isn't useful here, as it triggers an extra uncapitalise redirect, so we decode the path first * That encoding isn't useful here, as it triggers an extra uncapitalise redirect, so we decode the path first
*/ */
if (/[A-Z]/.test(decodedURI)) { if (/[A-Z]/.test(decodedURI)) {
redirectPath = ( redirectPath = (localUtils.removeOpenRedirectFromUrl((req.originalUrl || req.url).replace(pathToTest, pathToTest.toLowerCase())));
globalUtils.removeOpenRedirectFromUrl((req.originalUrl || req.url).replace(pathToTest, pathToTest.toLowerCase()))
);
return urlService.utils.redirect301(res, redirectPath); return urlService.utils.redirect301(res, redirectPath);
} }

View file

@ -1,7 +1,10 @@
var url = require('url'); 'use strict';
function removeDoubleCharacters(character, string) { const url = require('url');
var stringArray = string.split(''); let _private = {};
_private.removeDoubleCharacters = function removeDoubleCharacters(character, string) {
let stringArray = string.split('');
return stringArray.reduce(function (newString, currentCharacter, index) { return stringArray.reduce(function (newString, currentCharacter, index) {
if ( if (
@ -13,19 +16,17 @@ function removeDoubleCharacters(character, string) {
return newString + currentCharacter; return newString + currentCharacter;
}, ''); }, '');
} };
function removeOpenRedirectFromUrl(urlString) { module.exports.removeOpenRedirectFromUrl = function removeOpenRedirectFromUrl(urlString) {
var parsedUrl = url.parse(urlString); let parsedUrl = url.parse(urlString);
return ( return (
// http:// // http://
(parsedUrl.protocol ? parsedUrl.protocol + '//' : '') + (parsedUrl.protocol ? parsedUrl.protocol + '//' : '') +
(parsedUrl.auth || '') + (parsedUrl.auth || '') +
(parsedUrl.host || '') + (parsedUrl.host || '') +
removeDoubleCharacters('/', parsedUrl.path) + _private.removeDoubleCharacters('/', parsedUrl.path) +
(parsedUrl.hash || '') (parsedUrl.hash || '')
); );
} };
module.exports = removeOpenRedirectFromUrl;