Properly detect null value params in params conditions
Issue: SPR-15831
This commit is contained in:
parent
ca0983cd85
commit
4fc0ce1206
|
|
@ -51,6 +51,12 @@ public class ParamsRequestConditionTests {
|
|||
assertNotNull(condition.getMatchingCondition(get("/path?foo=").toExchange()));
|
||||
}
|
||||
|
||||
@Test // SPR-15831
|
||||
public void paramPresentNullValue() throws Exception {
|
||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
|
||||
assertNotNull(condition.getMatchingCondition(get("/path?foo").toExchange()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paramPresentNoMatch() throws Exception {
|
||||
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
|
||||
|
|
|
|||
|
|
@ -142,7 +142,8 @@ public final class ParamsRequestCondition extends AbstractRequestCondition<Param
|
|||
|
||||
@Override
|
||||
protected boolean matchName(HttpServletRequest request) {
|
||||
return WebUtils.hasSubmitParameter(request, this.name);
|
||||
return WebUtils.hasSubmitParameter(request, this.name) ||
|
||||
request.getParameterMap().containsKey(this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -23,7 +23,11 @@ import org.junit.Test;
|
|||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.web.servlet.mvc.condition.ParamsRequestCondition.ParamExpression;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ParamsRequestCondition}.
|
||||
|
|
@ -48,6 +52,14 @@ public class ParamsRequestConditionTests {
|
|||
assertNotNull(new ParamsRequestCondition("foo").getMatchingCondition(request));
|
||||
}
|
||||
|
||||
@Test // SPR-15831
|
||||
public void paramPresentNullValue() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("foo", (String) null);
|
||||
|
||||
assertNotNull(new ParamsRequestCondition("foo").getMatchingCondition(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paramPresentNoMatch() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
|
|
|||
Loading…
Reference in New Issue