Skip to content

Node.js based forum software built for the modern web

fix: #14121, use normalizedPath when uploading

Barış Soner Uşaklıa10471fce766
diff --git a/src/user/picture.js b/src/user/picture.js
index db135b463f..fe8a99c9a8 100644
--- a/src/user/picture.js
+++ b/src/user/picture.js
@@ -143,7 +143,7 @@ module.exports = function (User) {
const filename = generateProfileImageFilename(updateUid, extension);
const uploadedImage = await image.uploadImage(filename, `profile/uid-${updateUid}`, {
uid: updateUid,
- path: picture.path,
+ path: normalizedPath,
name: 'profileAvatar',
});
diff --git a/test/user.js b/test/user.js
index f6619bd651..cd0ba94e57 100644
--- a/test/user.js
+++ b/test/user.js
@@ -1144,6 +1144,30 @@ describe('User', () => {
});
});
+ it('should normalize uploaded image to png', async () => {
+ const oldValue = meta.config['profile:convertProfileImageToPNG'];
+ meta.config['profile:convertProfileImageToPNG'] = 1;
+
+ const uid = await User.create({ username: 'pngnormalize', password: '123456' });
+ const { jar, csrf_token } = await helpers.loginUser('pngnormalize', '123456');
+ const pathToJpeg = path.join(__dirname, '../test/files/normalise.jpg');
+
+ const { response } = await helpers.uploadFile(
+ `${nconf.get('url')}/api/user/pngnormalize/uploadpicture`,
+ pathToJpeg, { }, jar, csrf_token
+ );
+ assert.strictEqual(response.statusCode, 200);
+ const picture = await db.getObjectField(`user:${uid}`, 'picture');
+ const uploadedPath = path.join(
+ nconf.get('upload_path'), `${picture.replace(nconf.get('upload_url'), '')}`
+ );
+ const sharp = require('sharp');
+ const metadata = await sharp(uploadedPath).metadata();
+ assert.strictEqual(metadata.format, 'png');
+
+ meta.config['profile:convertProfileImageToPNG'] = oldValue;
+ });
+
it('should not allow image data with bad MIME type to be passed in', (done) => {
User.uploadCroppedPicture({
callerUid: uid,