Skip to content

Commit 4fc0ce1

Browse files
committed
Properly detect null value params in params conditions
Issue: SPR-15831
1 parent ca0983c commit 4fc0ce1

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/ParamsRequestConditionTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public void paramPresent() throws Exception {
5151
assertNotNull(condition.getMatchingCondition(get("/path?foo=").toExchange()));
5252
}
5353

54+
@Test // SPR-15831
55+
public void paramPresentNullValue() throws Exception {
56+
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
57+
assertNotNull(condition.getMatchingCondition(get("/path?foo").toExchange()));
58+
}
59+
5460
@Test
5561
public void paramPresentNoMatch() throws Exception {
5662
ParamsRequestCondition condition = new ParamsRequestCondition("foo");

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ParamsRequestCondition.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ protected String parseValue(String valueExpression) {
142142

143143
@Override
144144
protected boolean matchName(HttpServletRequest request) {
145-
return WebUtils.hasSubmitParameter(request, this.name);
145+
return WebUtils.hasSubmitParameter(request, this.name) ||
146+
request.getParameterMap().containsKey(this.name);
146147
}
147148

148149
@Override

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/ParamsRequestConditionTests.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,11 @@
2323
import org.springframework.mock.web.test.MockHttpServletRequest;
2424
import org.springframework.web.servlet.mvc.condition.ParamsRequestCondition.ParamExpression;
2525

26-
import static org.junit.Assert.*;
26+
import static org.junit.Assert.assertEquals;
27+
import static org.junit.Assert.assertFalse;
28+
import static org.junit.Assert.assertNotNull;
29+
import static org.junit.Assert.assertNull;
30+
import static org.junit.Assert.assertTrue;
2731

2832
/**
2933
* Unit tests for {@link ParamsRequestCondition}.
@@ -48,6 +52,14 @@ public void paramPresent() {
4852
assertNotNull(new ParamsRequestCondition("foo").getMatchingCondition(request));
4953
}
5054

55+
@Test // SPR-15831
56+
public void paramPresentNullValue() {
57+
MockHttpServletRequest request = new MockHttpServletRequest();
58+
request.addParameter("foo", (String) null);
59+
60+
assertNotNull(new ParamsRequestCondition("foo").getMatchingCondition(request));
61+
}
62+
5163
@Test
5264
public void paramPresentNoMatch() {
5365
MockHttpServletRequest request = new MockHttpServletRequest();

0 commit comments

Comments
 (0)