Skip to content

Commit 4735e8f

Browse files
Copilotruibaby
andauthored
fix: only append ?v to asset links that have no query params
Agent-Logs-Url: https://github.com/halo-dev/halo/sessions/7742a189-6a24-448d-8614-a276ebddb8d5 Co-authored-by: ruibaby <21301288+ruibaby@users.noreply.github.com>
1 parent 44857b5 commit 4735e8f

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

application/src/main/java/run/halo/app/theme/ThemeLinkBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected String processLink(IExpressionContext context, String link) {
4040
var path = PathUtils.combinePath(THEME_PREVIEW_PREFIX, theme.getName(), link);
4141
var uriComponents = UriComponentsBuilder.fromUriString(path).build();
4242
if (StringUtils.isNotBlank(theme.getVersion())
43-
&& uriComponents.getQueryParams().get("v") == null) {
43+
&& uriComponents.getQueryParams().isEmpty()) {
4444
return UriComponentsBuilder.fromUriString(path)
4545
.queryParam("v", theme.getVersion())
4646
.build().toString();

application/src/test/java/run/halo/app/theme/ThemeLinkBuilderTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,20 @@ void processAssetsLinkWithoutVersion() {
8282
}
8383

8484
@Test
85-
void processAssetsLinkWithExistingVersionParam() {
86-
// link that already has a v= parameter should not get another one appended
85+
void processAssetsLinkWithExistingQueryParams() {
86+
// link that already has any query parameter should not get ?v appended
8787
ThemeLinkBuilder themeLinkBuilder =
8888
new ThemeLinkBuilder(getTheme(true), externalUrlSupplier);
8989

90+
// already has v param
9091
String link = "/assets/css/style.css?v=custom";
9192
String processed = themeLinkBuilder.processLink(null, link);
9293
assertThat(processed).isEqualTo("/themes/test-theme/assets/css/style.css?v=custom");
94+
95+
// has a different custom query param the theme itself added
96+
link = "/assets/css/style.css?foo=bar";
97+
processed = themeLinkBuilder.processLink(null, link);
98+
assertThat(processed).isEqualTo("/themes/test-theme/assets/css/style.css?foo=bar");
9399
}
94100

95101
@Test

0 commit comments

Comments
 (0)