Fix MockCookie parsing when attribute is omitted
Issue: SPR-17321, #1974
This commit is contained in:
parent
00353a073c
commit
1b8421c7fe
|
|
@ -80,7 +80,7 @@ public class MockCookie extends Cookie {
|
||||||
String name = cookieParts[0];
|
String name = cookieParts[0];
|
||||||
String[] valueAndDirectives = cookieParts[1].split("\\s*;\\s*", 2);
|
String[] valueAndDirectives = cookieParts[1].split("\\s*;\\s*", 2);
|
||||||
String value = valueAndDirectives[0];
|
String value = valueAndDirectives[0];
|
||||||
String[] directives = valueAndDirectives[1].split("\\s*;\\s*");
|
String[] directives = valueAndDirectives.length > 1 ? valueAndDirectives[1].split("\\s*;\\s*") : new String[0];
|
||||||
|
|
||||||
MockCookie cookie = new MockCookie(name, value);
|
MockCookie cookie = new MockCookie(name, value);
|
||||||
for (String directive : directives) {
|
for (String directive : directives) {
|
||||||
|
|
|
||||||
|
|
@ -544,6 +544,29 @@ public class MockHttpServletRequestTests {
|
||||||
request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
|
request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCookieParsing() {
|
||||||
|
MockCookie m = MockCookie.parse("foo=bar");
|
||||||
|
testCookie("foo", "bar", m);
|
||||||
|
m = MockCookie.parse("foo=bar;");
|
||||||
|
assertFalse(m.isHttpOnly());
|
||||||
|
assertFalse(m.getSecure());
|
||||||
|
testCookie("foo", "bar", m);
|
||||||
|
m = MockCookie.parse("foo=bar; HttpOnly");
|
||||||
|
testCookie("foo", "bar", m);
|
||||||
|
assertTrue(m.isHttpOnly());
|
||||||
|
assertFalse(m.getSecure());
|
||||||
|
m = MockCookie.parse("foo=bar; Secure");
|
||||||
|
testCookie("foo", "bar", m);
|
||||||
|
assertTrue(m.getSecure());
|
||||||
|
assertFalse(m.isHttpOnly());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testCookie(String name, String value, MockCookie mockCookie) {
|
||||||
|
assertEquals(name, mockCookie.getName());
|
||||||
|
assertEquals(value, mockCookie.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void assertEqualEnumerations(Enumeration<?> enum1, Enumeration<?> enum2) {
|
private void assertEqualEnumerations(Enumeration<?> enum1, Enumeration<?> enum2) {
|
||||||
assertNotNull(enum1);
|
assertNotNull(enum1);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue