This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 9fd4c840f8726551915b93080ed5dcf926eb5a1c Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Jan 8 19:29:49 2024 +0000 A null value should remove the attribute --- java/jakarta/servlet/http/Cookie.java | 6 +++++- .../apache/tomcat/util/http/TestCookieProcessorGeneration.java | 8 ++++++++ webapps/docs/changelog.xml | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/java/jakarta/servlet/http/Cookie.java b/java/jakarta/servlet/http/Cookie.java index 4fc87e5516..22ddc5d3ff 100644 --- a/java/jakarta/servlet/http/Cookie.java +++ b/java/jakarta/servlet/http/Cookie.java @@ -409,7 +409,11 @@ public class Cookie implements Cloneable, Serializable { } } - attributes.put(name, value); + if (value == null) { + attributes.remove(name); + } else { + attributes.put(name, value); + } } diff --git a/test/org/apache/tomcat/util/http/TestCookieProcessorGeneration.java b/test/org/apache/tomcat/util/http/TestCookieProcessorGeneration.java index 43ac4d0ffd..3079f423f8 100644 --- a/test/org/apache/tomcat/util/http/TestCookieProcessorGeneration.java +++ b/test/org/apache/tomcat/util/http/TestCookieProcessorGeneration.java @@ -95,6 +95,14 @@ public class TestCookieProcessorGeneration { doTest(cookie, "foo=" + value); } + @Test + public void valueNull() { + Cookie cookie = new Cookie("foo", "bar"); + cookie.setAttribute("other", "anything"); + cookie.setAttribute("other", null); + doTest(cookie, "foo=bar"); + } + @Test public void testMaxAgePositive() { doTestMaxAge(100, "foo=bar; Max-Age=100"); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 7d752ad772..da9d7b705d 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -105,6 +105,14 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 11.0.0-M17 (markt)" rtext="in development"> + <subsection name="Coyote"> + <changelog> + <fix> + Setting a <code>null</code> value for a cookie attribute should remove + the attribute. (markt) + </fix> + </changelog> + </subsection> </section> <section name="Tomcat 11.0.0-M16 (markt)" rtext="release in progress"> <subsection name="Catalina"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org