Skip to content

MongoDB fails to connect when credentials contain a space - #52121

Merged
snicoll merged 1 commit into
spring-projects:4.0.xfrom
CCCLL:fix/mongodb-credential-spaces
Oct 12, 2026
Merged

snicoll merged 1 commit into
spring-projects:4.0.xfrom
CCCLL:fix/mongodb-credential-spaces

Conversation

@CCCLL

@CCCLL CCCLL commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

When spring.mongodb.username or spring.mongodb.password contains a space, PropertiesMongoConnectionDetails encodes it as +. The MongoDB driver treats that character as a literal plus sign, so a configured password such as my secret becomes my+secret in the parsed credentials.

Encode spaces as %20, matching the Docker Compose handling added in #51939, and reuse the string encoder for passwords. Add regression tests for both properties covering spaces, literal plus signs, a mixture of the two, and reserved characters.

Validation:

  • The four regression cases containing spaces fail before the fix and pass afterwards.
  • :module:spring-boot-mongodb:test: 108 tests passed.
  • :module:spring-boot-mongodb:checkFormat, :module:spring-boot-mongodb:checkstyleMain, and :module:spring-boot-mongodb:checkstyleTest passed.

Tested on the current main branch (535d133b) with JDK 25. Docker-based integration tests were not run.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Oct 9, 2026
prashantpiyush1111

This comment was marked as low quality.

@wilkinsona

Copy link
Copy Markdown
Member

@prashantpiyush1111 your comment appears to be AI generated. As such, it isn't helpful. If we want an AI's review of the changes, we can get one ourselves. What is helpful is bringing a different human perspective to a change as we have very limited access to those.

@prashantpiyush1111

Copy link
Copy Markdown

@wilkinsona Thanks for the feedback. I know what you mean. I was going to go through the changes and post my observations. I agree that reviews are most helpful when they are from an independent human point of view. I’ll keep this in mind and will try to focus on providing specific personal observations in future reviews.

@snicoll snicoll changed the title Preserve spaces in MongoDB property credentials MongoDB fails to connect when credentials contain a space Oct 12, 2026
@snicoll snicoll self-assigned this Oct 12, 2026
@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Oct 12, 2026
@snicoll snicoll added this to the 4.0.9 milestone Oct 12, 2026
Encode spaces as percent escapes when creating a connection string from
MongoDB username and password properties so the driver does not
interpret them as literal plus signs. Reuse the string encoder for
passwords and add regression tests for both credential properties.

See spring-projectsgh-52121

Signed-off-by: Jialin Chen <cccll2019@gmail.com>
@snicoll
snicoll force-pushed the fix/mongodb-credential-spaces branch from 9d37e52 to 98fd227 Compare October 12, 2026 13:17
@snicoll
snicoll changed the base branch from main to 4.0.x October 12, 2026 13:17
@snicoll
snicoll merged commit 09021e0 into spring-projects:4.0.x Oct 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants