From d443c3ed29a9e6dc61514d957c56ef9714c64e9a Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Sat, 7 Oct 2023 18:42:45 +0800 Subject: [PATCH] fix: incorrect truncation of CSS resource reads (#4678) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area core /milestone 2.10.x #### What this PR does / why we need it: 修复插件 css bundle 内容被错误拆分导致无法加载的问题 #### Which issue(s) this PR fixes: Fixes #4677 #### Does this PR introduce a user-facing change? ```release-note 修复插件 css bundle 内容被错误拆分导致无法加载的问题 ``` --- .../extension/service/impl/PluginServiceImpl.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/run/halo/app/core/extension/service/impl/PluginServiceImpl.java b/application/src/main/java/run/halo/app/core/extension/service/impl/PluginServiceImpl.java index ab029aa69d..7db4fb7ca6 100644 --- a/application/src/main/java/run/halo/app/core/extension/service/impl/PluginServiceImpl.java +++ b/application/src/main/java/run/halo/app/core/extension/service/impl/PluginServiceImpl.java @@ -26,7 +26,6 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.stereotype.Component; import org.springframework.util.Assert; -import org.springframework.util.StreamUtils; import org.springframework.web.server.ServerWebInputException; import reactor.core.Exceptions; import reactor.core.publisher.Flux; @@ -179,9 +178,15 @@ public Flux uglifyCssBundle() { return BundleResourceUtils.getJsBundleResource(pluginManager, pluginName, BundleResourceUtils.CSS_BUNDLE); }) - .flatMap(resource -> DataBufferUtils.read(resource, - DefaultDataBufferFactory.sharedInstance, StreamUtils.BUFFER_SIZE) - ); + .flatMap(resource -> { + try { + return DataBufferUtils.read(resource, DefaultDataBufferFactory.sharedInstance, + (int) resource.contentLength()); + } catch (IOException e) { + log.error("Failed to read plugin css bundle resource", e); + return Flux.empty(); + } + }); } @Override