Skip to content

Commit

Permalink
fix: resolve npe exception when request params are matched and removed
Browse files Browse the repository at this point in the history
  • Loading branch information
DanLi39 committed Jan 2, 2024
1 parent c45700c commit 60a748a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static boolean matchAndRemoveRequestParams(Map<String, List<String>> requ
Iterator<String> iterator = values.iterator();
while (iterator.hasNext()) {
String next = iterator.next();
if (next.equals(value)) {
if (StringUtil.equals(next, value)) {
iterator.remove();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ public void getFullPath() {
@Test
public void matchRequestParams() {
Map<String, List<String>> requestParams = new HashMap<>();
requestParams.put("name", new ArrayList<>(Arrays.asList("kimi")));
requestParams.put("name", new ArrayList<>(Arrays.asList("kimi", null)));
requestParams.put("age", new ArrayList<>(Arrays.asList("0")));
assertFalse(ServletUtil.matchAndRemoveRequestParams(requestParams, "name", "lock"));

//requestParams has null value,targetValue is not null
assertTrue(ServletUtil.matchAndRemoveRequestParams(requestParams, "age", "0"));

//test: requestParams has null value, and targetValue is null
assertTrue(ServletUtil.matchAndRemoveRequestParams(requestParams, "name", null));

assertFalse(ServletUtil.matchAndRemoveRequestParams(Collections.emptyMap(), "name", "lock"));
}

Expand Down

0 comments on commit 60a748a

Please sign in to comment.