Set cookie path to context path without trailing slash
Closes gh-1863
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -432,7 +432,8 @@ public class DefaultCookieSerializer implements CookieSerializer {
|
||||
|
||||
private String getCookiePath(HttpServletRequest request) {
|
||||
if (this.cookiePath == null) {
|
||||
return request.getContextPath() + "/";
|
||||
String contextPath = request.getContextPath();
|
||||
return (contextPath != null && contextPath.length() > 0) ? contextPath : "/";
|
||||
}
|
||||
return this.cookiePath;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -109,7 +109,7 @@ class CookieHttpSessionIdResolverTests {
|
||||
this.strategy.setSessionId(this.request, this.response, this.session.getId());
|
||||
|
||||
Cookie sessionCookie = this.response.getCookie(this.cookieName);
|
||||
assertThat(sessionCookie.getPath()).isEqualTo(this.request.getContextPath() + "/");
|
||||
assertThat(sessionCookie.getPath()).isEqualTo(this.request.getContextPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,7 +131,7 @@ class CookieHttpSessionIdResolverTests {
|
||||
this.strategy.expireSession(this.request, this.response);
|
||||
|
||||
Cookie sessionCookie = this.response.getCookie(this.cookieName);
|
||||
assertThat(sessionCookie.getPath()).isEqualTo(this.request.getContextPath() + "/");
|
||||
assertThat(sessionCookie.getPath()).isEqualTo(this.request.getContextPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -267,7 +267,7 @@ class DefaultCookieSerializerTests {
|
||||
void writeCookieCookiePathDefaultContextPathUsed() {
|
||||
this.request.setContextPath("/context");
|
||||
this.serializer.writeCookieValue(cookieValue(this.sessionId));
|
||||
assertThat(getCookie().getPath()).isEqualTo("/context/");
|
||||
assertThat(getCookie().getPath()).isEqualTo("/context");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -275,7 +275,7 @@ class DefaultCookieSerializerTests {
|
||||
this.request.setContextPath("/context");
|
||||
this.serializer.setCookiePath(null);
|
||||
this.serializer.writeCookieValue(cookieValue(this.sessionId));
|
||||
assertThat(getCookie().getPath()).isEqualTo("/context/");
|
||||
assertThat(getCookie().getPath()).isEqualTo("/context");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user