Skip to content

Update MockCookie#parse(String) validation - #37134

Merged
sbrannen merged 2 commits into
spring-projects:mainfrom
ngocnhan-tran1996:update-mock-cookie
Aug 13, 2026
Merged

Update MockCookie#parse(String) validation#37134
sbrannen merged 2 commits into
spring-projects:mainfrom
ngocnhan-tran1996:update-mock-cookie

Conversation

@ngocnhan-tran1996

Copy link
Copy Markdown
Contributor

* Factory method that parses the value of the supplied "Set-Cookie" header.
* @param setCookieHeader the "Set-Cookie" value; never {@code null} or empty
* @return the created cookie

Based on the Javadoc, I think it should throw Set-Cookie header must not be null or empty instead of Invalid Set-Cookie header '' when setCookieHeader is empty.

Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 13, 2026
@sbrannen sbrannen self-assigned this Aug 13, 2026
@sbrannen sbrannen added in: test Issues in the test module type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 13, 2026
@sbrannen sbrannen added this to the 7.1.0-M2 milestone Aug 13, 2026

@sbrannen sbrannen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! 👍

I've requested a minor change to the test.

Also, please update the duplicate variant of this class: spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockCookie.java

Thanks

Comment on lines +124 to +131
@Test
void parseEmptyHeader() {
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(""))
.withMessageContaining("Set-Cookie header must not be null or empty");
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(" "))
.withMessageContaining("Set-Cookie header must not be null or empty");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Test
void parseEmptyHeader() {
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(""))
.withMessageContaining("Set-Cookie header must not be null or empty");
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(" "))
.withMessageContaining("Set-Cookie header must not be null or empty");
@ParameterizedTest
@ValueSource(strings = {"", " "})
void parseEmptyHeader(String header) {
assertThatIllegalArgumentException()
.isThrownBy(() -> MockCookie.parse(header))
.withMessageContaining("Set-Cookie header must not be null or empty");
}

A @ParameterizedTest would be better here.

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Aug 13, 2026
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
@sbrannen sbrannen removed the status: waiting-for-feedback We need additional information before we can continue label Aug 13, 2026

@sbrannen sbrannen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the requested changes.

Looks good now.

@sbrannen
sbrannen merged commit 8b89493 into spring-projects:main Aug 13, 2026
2 checks passed
@sbrannen sbrannen modified the milestones: 7.1.0-M2, 7.1.0-M1 Aug 13, 2026
sbrannen added a commit that referenced this pull request Aug 13, 2026
@sbrannen

Copy link
Copy Markdown
Member

This has been merged into main in 8b89493 and slightly revised in 27a85be (since I realized after the merge that we can actually combine the "null" and "empty" tests into a single test method).

Thanks

@ngocnhan-tran1996
ngocnhan-tran1996 deleted the update-mock-cookie branch August 13, 2026 11:18
sbrannen added a commit that referenced this pull request Aug 13, 2026
This reverts commit 27a85be due to
code freeze on main.

See gh-37134
sbrannen added a commit that referenced this pull request Aug 13, 2026
…vadoc"

This reverts commit 8b89493 due to
code freeze on main.

See gh-37134
@sbrannen

Copy link
Copy Markdown
Member

Hi @ngocnhan-tran1996,

Due to a code freeze on main, I reverted those two commits via 951c1f3 and e78d3df.

After the 7.1 M1 release, I will cherry pick those two commits back on top of main for inclusion in 7.1 M2, retaining you as the author of your commit.

In light of that, can you please create a new issue (not a PR) with the title and body of this PR, referencing the two original commits (8b89493 and 27a85be) to be applied?

Or if you'd prefer that I do that, just let me know.

I apologize for the inconvenience.

Regards,

Sam

@sbrannen sbrannen removed this from the 7.1.0-M1 milestone Aug 13, 2026
@ngocnhan-tran1996

Copy link
Copy Markdown
Contributor Author

Hi @sbrannen

I created issue #37136. Please let me know if the content needs to be changed.

@sbrannen sbrannen added the status: superseded An issue that has been superseded by another label Aug 13, 2026
@sbrannen

Copy link
Copy Markdown
Member

I created issue #37136. Please let me know if the content needs to be changed.

That looks perfect. Thanks, @ngocnhan-tran1996. 👍

I've now labeled this PR as:

And I've already assigned that issue to the 7.1 M2 milestone.

Cheers,

Sam

sbrannen pushed a commit that referenced this pull request Aug 18, 2026
See gh-37134
Closes gh-37136

Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
sbrannen added a commit that referenced this pull request Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: test Issues in the test module status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants