0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-15 03:01:37 -05:00

🐛 Handled trailing slashes in resized image URLs

no issue

- requests for resized images with a trailing slash would end up
  throwing a EISDIR error because it got through to writing an
  image buffer to a directory
- we want to cut this off early and disallow trailing slashes
This commit is contained in:
Daniel Lockyer 2020-01-18 13:38:16 +07:00
parent af4ecb7b76
commit dbcffe9245

View file

@ -4,12 +4,17 @@ const storage = require('../../../../adapters/storage');
const activeTheme = require('../../../../../frontend/services/themes/active');
const SIZE_PATH_REGEX = /^\/size\/([^/]+)\//;
const NO_TRAILING_SLASH_REGEX = /\/+$/;
module.exports = function (req, res, next) {
if (!SIZE_PATH_REGEX.test(req.url)) {
return next();
}
if (NO_TRAILING_SLASH_REGEX.test(req.url)) {
return next();
}
const [sizeImageDir, requestedDimension] = req.url.match(SIZE_PATH_REGEX);
const redirectToOriginal = () => {
const url = req.originalUrl.replace(`/size/${requestedDimension}`, '');