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