mirror of https://github.com/halo-dev/halo
[release-2.17] Respond 404 for non-exist theme resources instead of 500 (#6355)
This is an automated cherry-pick of #6340 /assign JohnNiang ```release-note 修复访问不存在的主题资源时出现服务器异常的问题 ```pull/6374/head
parent
6d4beddaa9
commit
19e45e0d3c
|
@ -80,6 +80,9 @@ public class ThemeWebFluxConfigurer implements WebFluxConfigurer {
|
||||||
var assetsPath = themeRoot.resolve(themeName + "/templates/assets/" + resourcePaths);
|
var assetsPath = themeRoot.resolve(themeName + "/templates/assets/" + resourcePaths);
|
||||||
FileUtils.checkDirectoryTraversal(themeRoot, assetsPath);
|
FileUtils.checkDirectoryTraversal(themeRoot, assetsPath);
|
||||||
var location = new FileSystemResource(assetsPath);
|
var location = new FileSystemResource(assetsPath);
|
||||||
|
if (!location.isReadable()) {
|
||||||
|
return Mono.empty();
|
||||||
|
}
|
||||||
return Mono.just(location);
|
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