Node.js based forum software built for the modern web
fix: closes #14919, ignore @ suffixes in upload paths
Barış Soner Uşaklı6c82eec27b25
diff --git a/src/posts/uploads.js b/src/posts/uploads.jsindex f415db3a9b..749b0b2cc9 100644--- a/src/posts/uploads.js+++ b/src/posts/uploads.js@@ -22,7 +22,7 @@ module.exports = function (Posts) {const md5 = filename => crypto.createHash('md5').update(filename).digest('hex');const upload_path = nconf.get('upload_path');- const searchRegex = /\/assets\/uploads(\/files\/[^\s")]+\.?[\w]*)/g;+ const searchRegex = /\/assets\/uploads(\/files\/[^\s")@]+\.?[\w]*)/g;const _getFullPath = relativePath => path.join(upload_path, relativePath);const _filterValidPaths = async function (filePaths) {diff --git a/test/uploads.js b/test/uploads.jsindex 57638f1e0a..1f50cbb51e 100644--- a/test/uploads.js+++ b/test/uploads.js@@ -1,6 +1,5 @@'use strict';-const async = require('async');const assert = require('assert');const nconf = require('nconf');const path = require('path');@@ -851,5 +850,37 @@ describe('Upload Controllers', () => {meta.config.orphanExpiryDays = _orphanExpiryDays;});});++ describe('.getUploadsForPost() should ignore @ suffixes after file path', () => {+ let relPath;+ const relativePath = nconf.get('relative_path') || '';+ before(async () => {+ const { jar, csrf_token } = await helpers.loginUser('regular', 'zugzug');+ const { body } = await helpers.uploadFile(`${nconf.get('url')}/api/post/upload`, path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token);+ relPath = body.response.images[0].url.slice(body.response.images[0].url.indexOf('/files/'));+ });++ it('should strip a width x height suffix (@1920x1080)', async () => {+ const content = ``;+ const uploads = await posts.uploads.getUploadsForPost({ tid: 0, content }, false);+ assert.deepStrictEqual(uploads, [relPath]);+ });++ it('should strip a percentage suffix (@50%)', async () => {+ const content = ``;+ const uploads = await posts.uploads.getUploadsForPost({ tid: 0, content }, false);+ assert.deepStrictEqual(uploads, [relPath]);+ });++ it('should strip a width-only/multiplier suffix (@200)', async () => {+ const content = ``;+ const uploads = await posts.uploads.getUploadsForPost({ tid: 0, content }, false);+ assert.deepStrictEqual(uploads, [relPath]);+ });++ after(async () => {+ await emptyUploadsFolder();+ });+ });});});