Skip to content

Commit

Permalink
[release-2.17] Respond 404 for non-exist theme resources instead of 5…
Browse files Browse the repository at this point in the history
…00 (#6355)

This is an automated cherry-pick of #6340

/assign JohnNiang

```release-note
修复访问不存在的主题资源时出现服务器异常的问题
```
  • Loading branch information
halo-dev-bot authored Jul 22, 2024
1 parent 6d4bedd commit 19e45e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ protected Mono<Resource> resolveResourceInternal(ServerWebExchange exchange,
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,14 @@ void shouldResponseNotFoundWhenAssetsNotExist() {
}
}

@Nested
class StaticResourcesTest {

@Test
void shouldRespond404WhenThemeResourceNotFound() {
webClient.get().uri("/themes/fake-theme/assets/favicon.ico")
.exchange()
.expectStatus().isNotFound();
}
}
}

0 comments on commit 19e45e0

Please sign in to comment.