fix: #14121, use normalizedPath when uploading

add test for normalize
This commit is contained in:
Barış Soner Uşaklı
2026-03-24 12:43:57 -04:00
parent 9b88516250
commit a10471fce7
2 changed files with 25 additions and 1 deletions

View File

@@ -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',
});

View File

@@ -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,