(tomcat) 01/02: A null value should remove the attribute

2024-01-08 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 8c5f93c2823b4f3e52f54afa6dde32eb414e43a4
Author: Mark Thomas 
AuthorDate: Mon Jan 8 19:29:49 2024 +

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 6713f2dd93..8df4b785b5 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -105,6 +105,14 @@
   issues do not "pop up" wrt. others).
 -->
 
+  
+
+  
+Setting a null value for a cookie attribute should remove
+the attribute. (markt)
+  
+
+  
 
 
   


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



(tomcat) 01/02: A null value should remove the attribute

2024-01-08 Thread markt
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 
AuthorDate: Mon Jan 8 19:29:49 2024 +

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).
 -->
 
+  
+
+  
+Setting a null value for a cookie attribute should remove
+the attribute. (markt)
+  
+
+  
 
 
   


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org