diff --git a/application/src/main/java/run/halo/app/content/HtmlThumbnailSrcsetInjector.java b/application/src/main/java/run/halo/app/content/HtmlThumbnailSrcsetInjector.java index 55226e6af55..ccb03b81944 100644 --- a/application/src/main/java/run/halo/app/content/HtmlThumbnailSrcsetInjector.java +++ b/application/src/main/java/run/halo/app/content/HtmlThumbnailSrcsetInjector.java @@ -45,13 +45,17 @@ public static Mono injectSrcset(String html, static String buildSizesAttr() { var sb = new StringBuilder(); var delimiter = ", "; - for (ThumbnailSize size : ThumbnailSize.values()) { - sb.append("(max-width: ").append(size.getWidth()).append("px) ") + var sizes = ThumbnailSize.values(); + for (int i = 0; i < sizes.length; i++) { + var size = sizes[i]; + sb.append("(max-width: ").append(size.getWidth()).append("px)") + .append(" ") .append(size.getWidth()) - .append("px") - .append(delimiter); + .append("px"); + if (i < sizes.length - 1) { + sb.append(delimiter); + } } - sb.deleteCharAt(sb.length() - delimiter.length()); return sb.toString(); } diff --git a/application/src/test/java/run/halo/app/content/HtmlThumbnailSrcsetInjectorTest.java b/application/src/test/java/run/halo/app/content/HtmlThumbnailSrcsetInjectorTest.java index 3c4dbeefd37..5976457863a 100644 --- a/application/src/test/java/run/halo/app/content/HtmlThumbnailSrcsetInjectorTest.java +++ b/application/src/test/java/run/halo/app/content/HtmlThumbnailSrcsetInjectorTest.java @@ -25,9 +25,11 @@ void injectSrcset() { """; var result = HtmlThumbnailSrcsetInjector.injectSrcset(html, src -> Mono.just(src + " 480w, " + src + " 800w")).block(); - assertThat(result).isEqualTo(""" + assertThat(result).isEqualToIgnoringWhitespace("""
- test + test
""");