Skip to content

Commit

Permalink
Fix findUrlSuffix NPE when upgrading from an old version
Browse files Browse the repository at this point in the history
  • Loading branch information
longjuan committed Oct 27, 2023
1 parent c0fb2b1 commit fe8d742
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/run/halo/s3os/UrlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ public static String findUrlSuffix(List<S3OsProperties.urlSuffixItem> 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();
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/run/halo/s3os/UrlUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit fe8d742

Please sign in to comment.