From 6d446ba1b6d86b6bf6c26ce798689ebf0aa943da Mon Sep 17 00:00:00 2001 From: JFronny Date: Wed, 29 May 2024 15:10:49 +0200 Subject: [PATCH] fix: don't create files with bad names --- .../kotlin/io/gitlab/jfronny/sdom/actions/SDStatementAction.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/io/gitlab/jfronny/sdom/actions/SDStatementAction.kt b/src/main/kotlin/io/gitlab/jfronny/sdom/actions/SDStatementAction.kt index 7212442..6969110 100644 --- a/src/main/kotlin/io/gitlab/jfronny/sdom/actions/SDStatementAction.kt +++ b/src/main/kotlin/io/gitlab/jfronny/sdom/actions/SDStatementAction.kt @@ -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 }