mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-01 23:37:43 +03:00
Moved removeOpenRedirectFromUrl to local web utils
refs #9178 - see https://github.com/TryGhost/Ghost/issues/9178#issuecomment-351521897
This commit is contained in:
parent
485c264c69
commit
6e915e8e89
@ -132,7 +132,6 @@ utils = {
|
||||
},
|
||||
|
||||
readCSV: require('./read-csv'),
|
||||
removeOpenRedirectFromUrl: require('./remove-open-redirect-from-url'),
|
||||
zipFolder: require('./zip-folder'),
|
||||
generateAssetHash: require('./asset-hash'),
|
||||
tokens: require('./tokens'),
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
var urlService = require('../../services/url'),
|
||||
common = require('../../lib/common'),
|
||||
globalUtils = require('../../utils'),
|
||||
localUtils = require('../utils'),
|
||||
uncapitalise;
|
||||
|
||||
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
|
||||
*/
|
||||
if (/[A-Z]/.test(decodedURI)) {
|
||||
redirectPath = (
|
||||
globalUtils.removeOpenRedirectFromUrl((req.originalUrl || req.url).replace(pathToTest, pathToTest.toLowerCase()))
|
||||
);
|
||||
|
||||
redirectPath = (localUtils.removeOpenRedirectFromUrl((req.originalUrl || req.url).replace(pathToTest, pathToTest.toLowerCase())));
|
||||
return urlService.utils.redirect301(res, redirectPath);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
var url = require('url');
|
||||
'use strict';
|
||||
|
||||
function removeDoubleCharacters(character, string) {
|
||||
var stringArray = string.split('');
|
||||
const url = require('url');
|
||||
let _private = {};
|
||||
|
||||
_private.removeDoubleCharacters = function removeDoubleCharacters(character, string) {
|
||||
let stringArray = string.split('');
|
||||
|
||||
return stringArray.reduce(function (newString, currentCharacter, index) {
|
||||
if (
|
||||
@ -13,19 +16,17 @@ function removeDoubleCharacters(character, string) {
|
||||
|
||||
return newString + currentCharacter;
|
||||
}, '');
|
||||
}
|
||||
};
|
||||
|
||||
function removeOpenRedirectFromUrl(urlString) {
|
||||
var parsedUrl = url.parse(urlString);
|
||||
module.exports.removeOpenRedirectFromUrl = function removeOpenRedirectFromUrl(urlString) {
|
||||
let parsedUrl = url.parse(urlString);
|
||||
|
||||
return (
|
||||
// http://
|
||||
(parsedUrl.protocol ? parsedUrl.protocol + '//' : '') +
|
||||
(parsedUrl.auth || '') +
|
||||
(parsedUrl.host || '') +
|
||||
removeDoubleCharacters('/', parsedUrl.path) +
|
||||
_private.removeDoubleCharacters('/', parsedUrl.path) +
|
||||
(parsedUrl.hash || '')
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = removeOpenRedirectFromUrl;
|
||||
};
|
Loading…
Reference in New Issue
Block a user