From fe8d74265e61e08f4db8b2f4df6c5ccd60280fe9 Mon Sep 17 00:00:00 2001 From: longjuan <769022681@qq.com> Date: Fri, 27 Oct 2023 02:20:00 +0000 Subject: [PATCH] Fix findUrlSuffix NPE when upgrading from an old version --- src/main/java/run/halo/s3os/UrlUtils.java | 12 +++++++----- src/test/java/run/halo/s3os/UrlUtilsTest.java | 5 +++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/run/halo/s3os/UrlUtils.java b/src/main/java/run/halo/s3os/UrlUtils.java index a1c502c..0836ec9 100644 --- a/src/main/java/run/halo/s3os/UrlUtils.java +++ b/src/main/java/run/halo/s3os/UrlUtils.java @@ -25,11 +25,13 @@ public static String findUrlSuffix(List urlSuffixL return null; } fileName = fileName.toLowerCase(); - for (S3OsProperties.urlSuffixItem item : urlSuffixList) { - String[] fileSuffixes = item.getFileSuffix().split(","); - for (String suffix : fileSuffixes) { - if (fileName.endsWith("." + suffix.trim().toLowerCase())) { - return item.getUrlSuffix(); + if (urlSuffixList != null) { + for (S3OsProperties.urlSuffixItem item : urlSuffixList) { + String[] fileSuffixes = item.getFileSuffix().split(","); + for (String suffix : fileSuffixes) { + if (fileName.endsWith("." + suffix.trim().toLowerCase())) { + return item.getUrlSuffix(); + } } } } 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