fix: don't create files with bad names

This commit is contained in:
Johannes Frohnmeyer 2024-05-29 15:10:49 +02:00
parent 43278ee35d
commit 6d446ba1b6
Signed by: Johannes
GPG Key ID: E76429612C2929F4

View File

@ -59,7 +59,8 @@ class SDStatementAction(name: String) : DumbAwareAction(name) {
CoroutineScope(Job() + Dispatchers.IO).launch {
val data = SDom.downloadProblemStatement(contest, problem)
fun createTmpFile(): Path {
val path = Files.createTempFile("${problem.name}_${contest.name}", ".pdf")
val prefix = "${problem.name}_${contest.name}".replace("[^a-zA-Z0-9._-]".toRegex(), "_")
val path = Files.createTempFile(prefix, ".pdf")
Files.write(path, data, StandardOpenOption.WRITE)
return path
}