Sanitize file names on chat renaming
| @@ -8828,6 +8828,10 @@ export async function renameChat(oldFileName, newName) { | |||
| 8828 | throw new Error('Server returned an error.'); | 8828 | throw new Error('Server returned an error.'); |
| 8829 | } | 8829 | } |
| 8830 | 8830 | ||
| 8831 | if (data.sanitizedFileName) { | ||
| 8832 | newName = data.sanitizedFileName; | ||
| 8833 | } | ||
| 8834 | |||
| 8831 | if (selected_group) { | 8835 | if (selected_group) { |
| 8832 | await renameGroupChat(selected_group, oldFileName, newName); | 8836 | await renameGroupChat(selected_group, oldFileName, newName); |
| 8833 | } | 8837 | } |
| @@ -199,8 +199,9 @@ router.post('/rename', jsonParser, async function (request, response) { | |||
| 199 | const pathToFolder = request.body.is_group | 199 | const pathToFolder = request.body.is_group |
| 200 | ? request.user.directories.groupChats | 200 | ? request.user.directories.groupChats |
| 201 | : path.join(request.user.directories.chats, String(request.body.avatar_url).replace('.png', '')); | 201 | : path.join(request.user.directories.chats, String(request.body.avatar_url).replace('.png', '')); |
| 202 | const pathToOriginalFile = path.join(pathToFolder, request.body.original_file); | 202 | const pathToOriginalFile = path.join(pathToFolder, sanitize(request.body.original_file)); |
| 203 | const pathToRenamedFile = path.join(pathToFolder, request.body.renamed_file); | 203 | const pathToRenamedFile = path.join(pathToFolder, sanitize(request.body.renamed_file)); |
| 204 | const sanitizedFileName = path.parse(pathToRenamedFile).name; | ||
| 204 | console.log('Old chat name', pathToOriginalFile); | 205 | console.log('Old chat name', pathToOriginalFile); |
| 205 | console.log('New chat name', pathToRenamedFile); | 206 | console.log('New chat name', pathToRenamedFile); |
| 206 | 207 | ||
| @@ -212,7 +213,7 @@ router.post('/rename', jsonParser, async function (request, response) { | |||
| 212 | fs.copyFileSync(pathToOriginalFile, pathToRenamedFile); | 213 | fs.copyFileSync(pathToOriginalFile, pathToRenamedFile); |
| 213 | fs.rmSync(pathToOriginalFile); | 214 | fs.rmSync(pathToOriginalFile); |
| 214 | console.log('Successfully renamed.'); | 215 | console.log('Successfully renamed.'); |
| 215 | return response.send({ ok: true }); | 216 | return response.send({ ok: true, sanitizedFileName }); |
| 216 | }); | 217 | }); |
| 217 | 218 | ||
| 218 | router.post('/delete', jsonParser, function (request, response) { | 219 | router.post('/delete', jsonParser, function (request, response) { |