mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Support custom attribute with a value in MockCookie.parse()
Prior to this commit, MockCookie.parse() failed with an
IllegalArgumentException when attempting to parse a custom attribute
with a value, such as "Version=1". This is a regression that was
inadvertently introduced in 7fc4937199
when adding support for the "Partitioned" attribute which does not
support a value.
This commit addresses this regression by parsing both the name and the
value from an optional, custom attribute.
See gh-31454
Closes gh-34575
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 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.
|
||||
@@ -178,7 +178,8 @@ public class MockCookie extends Cookie {
|
||||
cookie.setComment(extractAttributeValue(attribute, setCookieHeader));
|
||||
}
|
||||
else if (!attribute.isEmpty()) {
|
||||
cookie.setAttribute(attribute, extractOptionalAttributeValue(attribute, setCookieHeader));
|
||||
String[] nameAndValue = extractOptionalAttributeNameAndValue(attribute, setCookieHeader);
|
||||
cookie.setAttribute(nameAndValue[0], nameAndValue[1]);
|
||||
}
|
||||
}
|
||||
return cookie;
|
||||
@@ -191,9 +192,9 @@ public class MockCookie extends Cookie {
|
||||
return nameAndValue[1];
|
||||
}
|
||||
|
||||
private static String extractOptionalAttributeValue(String attribute, String header) {
|
||||
private static String[] extractOptionalAttributeNameAndValue(String attribute, String header) {
|
||||
String[] nameAndValue = attribute.split("=");
|
||||
return nameAndValue.length == 2 ? nameAndValue[1] : "";
|
||||
return (nameAndValue.length == 2 ? nameAndValue : new String[] {attribute, ""});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user