From 565d3cfcaad1f2a2d95d6a1f98532aae5a17e9e3 Mon Sep 17 00:00:00 2001 From: longjuan <769022681@qq.com> Date: Fri, 27 Oct 2023 10:34:15 +0800 Subject: [PATCH] Fix findUrlSuffix NPE when upgrading from old version (#94) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes https://github.com/halo-dev/plugin-s3/issues/93 ```release-note 修复从旧版本升级后上传文件的NPE错误 ``` /kind bug --- src/main/java/run/halo/s3os/UrlUtils.java | 2 +- src/test/java/run/halo/s3os/UrlUtilsTest.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/run/halo/s3os/UrlUtils.java b/src/main/java/run/halo/s3os/UrlUtils.java index a1c502c..8b17f87 100644 --- a/src/main/java/run/halo/s3os/UrlUtils.java +++ b/src/main/java/run/halo/s3os/UrlUtils.java @@ -21,7 +21,7 @@ public static String removeHttpPrefix(String url) { public static String findUrlSuffix(List urlSuffixList, String fileName) { - if (StringUtils.isBlank(fileName)) { + if (StringUtils.isBlank(fileName) || urlSuffixList == null) { return null; } fileName = fileName.toLowerCase(); diff --git a/src/test/java/run/halo/s3os/UrlUtilsTest.java b/src/test/java/run/halo/s3os/UrlUtilsTest.java index aecb5a0..02b707b 100644 --- a/src/test/java/run/halo/s3os/UrlUtilsTest.java +++ b/src/test/java/run/halo/s3os/UrlUtilsTest.java @@ -46,5 +46,10 @@ public void testFindUrlSuffix() { String fileName5 = ""; String result5 = UrlUtils.findUrlSuffix(urlSuffixList, fileName5); assertNull(result5); + + // 测试urlSuffixList为null,期望返回null + String fileName6 = "example"; + String result6 = UrlUtils.findUrlSuffix(null, fileName6); + assertNull(result6); } } \ No newline at end of file