Skip to content

fix: Reading body() before or after form() is not consistent across a… - #4034

Open
jknack wants to merge 1 commit into
mainfrom
4031
Open

jknack wants to merge 1 commit into
mainfrom
4031

Conversation

@jknack

@jknack jknack commented Oct 27, 2026

Copy link
Copy Markdown
Member

…ll servers

fixes #4031

@jknack jknack added this to the 4.5.5 milestone Oct 27, 2026
@jknack jknack added the bug label Oct 27, 2026
@jknack

jknack commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

@froque please review

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.19%. Comparing base (28cc2d7) to head (7fac361).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #4034   +/-   ##
=========================================
  Coverage     94.19%   94.19%           
- Complexity     6676     6685    +9     
=========================================
  Files           432      432           
  Lines         20951    20960    +9     
  Branches       2106     2107    +1     
=========================================
+ Hits          19734    19744   +10     
  Misses          760      760           
+ Partials        457      456    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

}

private boolean isFormLike() {
var contentType = request.getHeaders().get(HttpHeader.CONTENT_TYPE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In my project unit tests, I am usingRestAssured that adds charset by default.

application/x-www-form-urlencoded;charset=iso-8859-1

Test against FORM_ENCODED_UTF_8 and FORM_ENCODED_8859_1 as well ?

Some reports indicate that charset is not valid here
request/request#701
spring-cloud/spring-cloud-gateway#3522
lysine-dev/okhttp#4210

But we should still not fail if it is sent.

}

@ServerTest
public void readFormDataBeforeBody(ServerTestRunner runner) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the test name is swapped. this should be readFormDataAfterBody

"/",
ctx -> {
try {
Assertions.assertAll(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I made a mistake, this is not how to use assertAll

assertAll(
  "Grouped Assertions of User",
  () -> assertEquals("admin", user.getUsername(), "Username should be admin"),
  () -> assertEquals("admin@baeldung.com", user.getEmail(), "Email should be admin@baeldung.com"),
  () -> assertTrue(user.getActivated(), "User should be activated")
);

https://www.baeldung.com/junit5-assertall-vs-multiple-assertions

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reading body() before or after form() is not consistent across all servers

2 participants