diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index 7b4a7bf342f..25d685f9101 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -75,9 +75,18 @@ export default abstract class Exporter { this.files.push(file); } + protected santizeFileName(filename: string): string { + filename = filename.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); + filename = filename.replace(/\s+/gim, "-"); + filename = filename.replace(/[^a-z0-9.,_-]/gim, ""); + return filename.trim(); + } + protected async downloadZIP(): Promise { const brand = SdkConfig.get().brand; - const filenameWithoutExt = `${brand} - Chat Export - ${formatFullDateNoDay(new Date())}`; + const filenameWithoutExt = this.santizeFileName( + `${brand} - ${this.room.name} - Chat Export - ${formatFullDateNoDay(new Date())}`, + ); const filename = `${filenameWithoutExt}.zip`; const { default: JSZip } = await import('jszip'); diff --git a/src/utils/exportUtils/JSONExport.ts b/src/utils/exportUtils/JSONExport.ts index b0b4b330b06..8a88b3204b9 100644 --- a/src/utils/exportUtils/JSONExport.ts +++ b/src/utils/exportUtils/JSONExport.ts @@ -108,7 +108,9 @@ export default class JSONExporter extends Exporter { this.addFile("export.json", new Blob([text])); await this.downloadZIP(); } else { - const fileName = `matrix-export-${formatFullDateNoDay(new Date())}.json`; + const fileName = this.santizeFileName( + `matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.json`, + ); this.downloadPlainText(fileName, text); } diff --git a/src/utils/exportUtils/PlainTextExport.ts b/src/utils/exportUtils/PlainTextExport.ts index e86c56e9f4c..04a5021d941 100644 --- a/src/utils/exportUtils/PlainTextExport.ts +++ b/src/utils/exportUtils/PlainTextExport.ts @@ -136,7 +136,9 @@ export default class PlainTextExporter extends Exporter { this.addFile("export.txt", new Blob([text])); await this.downloadZIP(); } else { - const fileName = `matrix-export-${formatFullDateNoDay(new Date())}.txt`; + const fileName = this.santizeFileName( + `matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.txt`, + ); this.downloadPlainText(fileName, text); }