mirror of https://github.com/halo-dev/halo
Respond 404 for non-exist theme resources instead of 500 (#6340)
#### What type of PR is this? /kind bug /area core /milestone 2.18.x #### What this PR does / why we need it: This PR checks readable of theme resources while getting resources to prevent Halo from throwing FileNotFoundException. #### Which issue(s) this PR fixes: Fixes #6338 #### Special notes for your reviewer: 1. Try to request <https://www.halo.run/themes/fake-theme/assets/favicons/favicon-32x32.png> 2. See the result #### Does this PR introduce a user-facing change? ```release-note 修复访问不存在的主题资源时出现服务器异常的问题 ```pull/6363/head
parent
2a807b748b
commit
1992916ab6
|
@ -80,6 +80,9 @@ public class ThemeWebFluxConfigurer implements WebFluxConfigurer {
|
|||
var assetsPath = themeRoot.resolve(themeName + "/templates/assets/" + resourcePaths);
|
||||
FileUtils.checkDirectoryTraversal(themeRoot, assetsPath);
|
||||
var location = new FileSystemResource(assetsPath);
|
||||
if (!location.isReadable()) {
|
||||
return Mono.empty();
|
||||
}
|
||||
return Mono.just(location);
|
||||
}
|
||||
|
||||
|
|
|
@ -144,4 +144,14 @@ class WebFluxConfigTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class StaticResourcesTest {
|
||||
|
||||
@Test
|
||||
void shouldRespond404WhenThemeResourceNotFound() {
|
||||
webClient.get().uri("/themes/fake-theme/assets/favicon.ico")
|
||||
.exchange()
|
||||
.expectStatus().isNotFound();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue