From 9bad78d55237b901a4646f8cec73cdd5c6f5f535 Mon Sep 17 00:00:00 2001 From: johnniang Date: Thu, 9 May 2019 22:24:54 +0800 Subject: [PATCH] Fix unsupported theme media type bug --- .../run/halo/app/service/impl/ThemeServiceImpl.java | 2 +- .../run/halo/app/service/support/HaloMediaType.java | 2 ++ src/test/java/run/halo/app/model/MediaTypeTest.java | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java index c6faa57a1..db20bd359 100644 --- a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java @@ -353,7 +353,7 @@ public class ThemeServiceImpl implements ThemeService { public ThemeProperty upload(MultipartFile file) { Assert.notNull(file, "Multipart file must not be null"); - if (!HaloMediaType.isZipType(file.getContentType())) { + if (!StringUtils.endsWithIgnoreCase(file.getOriginalFilename(), ".zip")) { throw new UnsupportedMediaTypeException("Unsupported theme media type: " + file.getContentType()).setErrorData(file.getOriginalFilename()); } diff --git a/src/main/java/run/halo/app/service/support/HaloMediaType.java b/src/main/java/run/halo/app/service/support/HaloMediaType.java index 18cc585cf..8c30d3722 100644 --- a/src/main/java/run/halo/app/service/support/HaloMediaType.java +++ b/src/main/java/run/halo/app/service/support/HaloMediaType.java @@ -70,6 +70,7 @@ public class HaloMediaType extends MediaType { * @param mediaType media type * @return true if the given media type is zip type; false otherwise */ + @Deprecated public static boolean isZipType(MediaType mediaType) { if (mediaType == null) { return false; @@ -84,6 +85,7 @@ public class HaloMediaType extends MediaType { * @param contentType content type * @return true if the given content type is zip type; false otherwise */ + @Deprecated public static boolean isZipType(String contentType) { if (StringUtils.isBlank(contentType)) { return false; diff --git a/src/test/java/run/halo/app/model/MediaTypeTest.java b/src/test/java/run/halo/app/model/MediaTypeTest.java index 8f04cadfe..8f359cfc0 100644 --- a/src/test/java/run/halo/app/model/MediaTypeTest.java +++ b/src/test/java/run/halo/app/model/MediaTypeTest.java @@ -1,7 +1,9 @@ package run.halo.app.model; +import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.springframework.http.MediaType; +import run.halo.app.service.support.HaloMediaType; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.*; @@ -10,6 +12,7 @@ import static org.junit.Assert.*; * @author johnniang * @date 3/26/19 */ +@Slf4j public class MediaTypeTest { @Test @@ -42,4 +45,12 @@ public class MediaTypeTest { isInclude = mediaType.includes(MediaType.TEXT_HTML); assertFalse(isInclude); } + + @Test + public void zipTest() { + MediaType mediaType = MediaType.valueOf("application/x-zip-compressed"); + log.debug("Zip type: [{}]", mediaType); + + assertFalse(HaloMediaType.isZipType(mediaType)); + } }