Skip to content

Commit 0b63053

Browse files
committed
refactor
1 parent 8f20b9f commit 0b63053

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/de/rwth/idsg/steve/web/controller/AboutSettingsController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import de.rwth.idsg.steve.web.dto.EndpointInfo;
3131
import de.rwth.idsg.steve.web.dto.SettingsForm;
3232
import lombok.RequiredArgsConstructor;
33+
import org.apache.commons.lang3.StringUtils;
3334
import org.joda.time.DateTime;
3435
import org.joda.time.DateTimeZone;
3536
import org.springframework.http.HttpHeaders;
@@ -135,7 +136,7 @@ public void exportZip(@ModelAttribute("exportForm") DataExportForm exportForm,
135136
HttpServletResponse response) throws IOException {
136137
String fileName = "data-export_" + System.currentTimeMillis() + ".zip";
137138
String headerKey = "Content-Disposition";
138-
String headerValue = String.format("attachment; filename=\"%s\"", fileName);
139+
String headerValue = "attachment; filename=\"%s\"".formatted(fileName);
139140
response.setHeader(headerKey, headerValue);
140141
response.setContentType("application/zip");
141142

@@ -148,7 +149,13 @@ public String importZip(@RequestParam("file") MultipartFile file, Model model) t
148149
throw new SteveException.BadRequest("File is empty");
149150
}
150151

151-
if (!file.getOriginalFilename().endsWith(".zip")) {
152+
String fileName = file.getOriginalFilename();
153+
154+
if (StringUtils.isEmpty(fileName)) {
155+
throw new SteveException.BadRequest("File name is empty");
156+
}
157+
158+
if (!fileName.endsWith(".zip")) {
152159
throw new SteveException.BadRequest("File must be a ZIP archive");
153160
}
154161

0 commit comments

Comments
 (0)