diff --git a/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java b/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java index e988d5e11..8d39fa729 100644 --- a/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java +++ b/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java @@ -236,8 +236,7 @@ public class WebMvcAutoConfiguration extends WebMvcConfigurationSupport { private void initBlackPatterns() { String uploadUrlPattern = ensureBoth(haloProperties.getUploadUrlPrefix(), URL_SEPARATOR) + "**"; - String adminPathPattern = ensureBoth(haloProperties.getAdminPath(), URL_SEPARATOR) + "**"; - + String adminPathPattern = ensureBoth(haloProperties.getAdminPath(), URL_SEPARATOR) + "?*/**"; blackPatterns.add("/themes/**"); blackPatterns.add("/js/**"); diff --git a/src/main/java/run/halo/app/controller/content/MainController.java b/src/main/java/run/halo/app/controller/content/MainController.java index ee122772a..4536edc1c 100644 --- a/src/main/java/run/halo/app/controller/content/MainController.java +++ b/src/main/java/run/halo/app/controller/content/MainController.java @@ -11,6 +11,7 @@ import run.halo.app.model.properties.BlogProperties; import run.halo.app.model.support.HaloConst; import run.halo.app.service.OptionService; import run.halo.app.service.UserService; +import run.halo.app.utils.HaloUtils; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @@ -48,7 +49,7 @@ public class MainController { @GetMapping("${halo.admin-path:admin}") public void admin(HttpServletResponse response) throws IOException { - String adminIndexRedirectUri = StringUtils.appendIfMissing(this.haloProperties.getAdminPath(), "/") + INDEX_REDIRECT_URI; + String adminIndexRedirectUri = HaloUtils.ensureBoth(haloProperties.getAdminPath(), HaloUtils.URL_SEPARATOR) + INDEX_REDIRECT_URI; response.sendRedirect(adminIndexRedirectUri); } diff --git a/src/test/java/run/halo/app/conf/AntPathMatcherTest.java b/src/test/java/run/halo/app/conf/AntPathMatcherTest.java new file mode 100644 index 000000000..2fe46e133 --- /dev/null +++ b/src/test/java/run/halo/app/conf/AntPathMatcherTest.java @@ -0,0 +1,24 @@ +package run.halo.app.conf; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.util.AntPathMatcher; + +/** + * Ant path matcher test. + * + * @author johnniang + */ +public class AntPathMatcherTest { + + private final AntPathMatcher pathMatcher = new AntPathMatcher(); + + @Test + public void matchTest() { + Assert.assertFalse(pathMatcher.match("/admin/?*/**", "/admin")); + Assert.assertFalse(pathMatcher.match("/admin/?*/**", "/admin/")); + + Assert.assertTrue(pathMatcher.match("/admin/?*/**", "/admin/index.html")); + Assert.assertTrue(pathMatcher.match("/admin/?*/**", "/admin/index.html/more")); + } +}