Skip to content

Commit 6e71828

Browse files
committed
Add space before cookie attributes
According to RFC-6265 that there should be a space between the ; and the attribute name, i.e. the header should be something like name=value; Domain=localhost; HttpOnly rather than name=value;Domain=localhost;HttpOnly Issue: SPR-15225
1 parent abe3cfd commit 6e71828

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -328,25 +328,25 @@ private String getCookieHeader(Cookie cookie) {
328328
StringBuilder buf = new StringBuilder();
329329
buf.append(cookie.getName()).append('=').append(cookie.getValue() == null ? "" : cookie.getValue());
330330
if (StringUtils.hasText(cookie.getPath())) {
331-
buf.append(";Path=").append(cookie.getPath());
331+
buf.append("; Path=").append(cookie.getPath());
332332
}
333333
if (StringUtils.hasText(cookie.getDomain())) {
334-
buf.append(";Domain=").append(cookie.getDomain());
334+
buf.append("; Domain=").append(cookie.getDomain());
335335
}
336336
int maxAge = cookie.getMaxAge();
337337
if (maxAge >= 0) {
338-
buf.append(";Max-Age=").append(maxAge);
339-
buf.append(";Expires=");
338+
buf.append("; Max-Age=").append(maxAge);
339+
buf.append("; Expires=");
340340
HttpHeaders headers = new HttpHeaders();
341341
headers.setExpires(maxAge > 0 ? System.currentTimeMillis() + 1000L * maxAge : 0);
342342
buf.append(headers.getFirst(HttpHeaders.EXPIRES));
343343
}
344344

345345
if (cookie.getSecure()) {
346-
buf.append(";Secure");
346+
buf.append("; Secure");
347347
}
348348
if (cookie.isHttpOnly()) {
349-
buf.append(";HttpOnly");
349+
buf.append("; HttpOnly");
350350
}
351351
return buf.toString();
352352
}

spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ public void cookies() {
168168

169169
response.addCookie(cookie);
170170

171-
assertEquals("foo=bar;Path=/path;Domain=example.com;" +
172-
"Max-Age=0;Expires=Thu, 01 Jan 1970 00:00:00 GMT;" +
173-
"Secure;HttpOnly", response.getHeader(HttpHeaders.SET_COOKIE));
171+
assertEquals("foo=bar; Path=/path; Domain=example.com; " +
172+
"Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; " +
173+
"Secure; HttpOnly", response.getHeader(HttpHeaders.SET_COOKIE));
174174
}
175175

176176
@Test

spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockWebResponseBuilderTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public void buildResponseHeaders() throws Exception {
116116
assertThat(header.getValue(), equalTo("value"));
117117
header = responseHeaders.get(2);
118118
assertThat(header.getName(), equalTo("Set-Cookie"));
119-
assertThat(header.getValue(), startsWith("cookieA=valueA;Path=/path;Domain=domain;Max-Age=1800;Expires="));
120-
assertThat(header.getValue(), endsWith(";Secure;HttpOnly"));
119+
assertThat(header.getValue(), startsWith("cookieA=valueA; Path=/path; Domain=domain; Max-Age=1800; Expires="));
120+
assertThat(header.getValue(), endsWith("; Secure; HttpOnly"));
121121
}
122122

123123
// SPR-14169

spring-test/src/test/java/org/springframework/test/web/servlet/result/PrintingResultHandlerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void printResponse() throws Exception {
120120
assertEquals(2, cookieValues.size());
121121
assertEquals("cookie=cookieValue", cookieValues.get(0));
122122
assertTrue("Actual: " + cookieValues.get(1), cookieValues.get(1).startsWith(
123-
"enigma=42;Path=/crumbs;Domain=.example.com;Max-Age=1234;Expires="));
123+
"enigma=42; Path=/crumbs; Domain=.example.com; Max-Age=1234; Expires="));
124124

125125
HttpHeaders headers = new HttpHeaders();
126126
headers.set("header", "headerValue");

spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -328,25 +328,25 @@ private String getCookieHeader(Cookie cookie) {
328328
StringBuilder buf = new StringBuilder();
329329
buf.append(cookie.getName()).append('=').append(cookie.getValue() == null ? "" : cookie.getValue());
330330
if (StringUtils.hasText(cookie.getPath())) {
331-
buf.append(";Path=").append(cookie.getPath());
331+
buf.append("; Path=").append(cookie.getPath());
332332
}
333333
if (StringUtils.hasText(cookie.getDomain())) {
334-
buf.append(";Domain=").append(cookie.getDomain());
334+
buf.append("; Domain=").append(cookie.getDomain());
335335
}
336336
int maxAge = cookie.getMaxAge();
337337
if (maxAge >= 0) {
338-
buf.append(";Max-Age=").append(maxAge);
339-
buf.append(";Expires=");
338+
buf.append("; Max-Age=").append(maxAge);
339+
buf.append("; Expires=");
340340
HttpHeaders headers = new HttpHeaders();
341341
headers.setExpires(maxAge > 0 ? System.currentTimeMillis() + 1000L * maxAge : 0);
342342
buf.append(headers.getFirst(HttpHeaders.EXPIRES));
343343
}
344344

345345
if (cookie.getSecure()) {
346-
buf.append(";Secure");
346+
buf.append("; Secure");
347347
}
348348
if (cookie.isHttpOnly()) {
349-
buf.append(";HttpOnly");
349+
buf.append("; HttpOnly");
350350
}
351351
return buf.toString();
352352
}

0 commit comments

Comments
 (0)