Skip to content

[FLINK-40957][connect/mongodb] Fix MongoDB credential encoding for spaces - #4568

Open
LuanaMihailescu wants to merge 6 commits into
apache:masterfrom
LuanaMihailescu:fix-mongodb-space-encoding
Open

LuanaMihailescu wants to merge 6 commits into
apache:masterfrom
LuanaMihailescu:fix-mongodb-space-encoding

Conversation

@LuanaMihailescu

Copy link
Copy Markdown

What is the purpose of this pull request?

This PR fixes the encoding of MongoDB credentials containing spaces.

MongoDBEnvelope.encodeValue() currently relies on URLEncoder, which encodes spaces as + according to application/x-www-form-urlencoded semantics. However, MongoDB connection URIs expect spaces to be percent-encoded as %20.

This change ensures that spaces are encoded as %20, preventing authentication issues when usernames or passwords contain spaces.

JIRA: FLINK-40957

Brief change log

  • Updated MongoDBEnvelope.encodeValue() to encode spaces as %20 instead of +
  • Added a unit test covering values that contain spaces

Verifying this change

This change added tests and can be verified as follows:

  • Added unit tests in MongoDBEnvelopeTest
  • Verified that MongoDBEnvelope.encodeValue("my pass") returned my+pass before the fix
  • Verified that MongoDBEnvelope.encodeValue("my pass") returns my%20pass after the fix

Documentation

  • Does this pull request introduce a new feature? No

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

@LuanaMihailescu
LuanaMihailescu force-pushed the fix-mongodb-space-encoding branch from 04b71f2 to 149b79e Compare October 12, 2026 11:24
@LuanaMihailescu LuanaMihailescu changed the title Fix MongoDB credential encoding for spaces [FLINK-40957][connect/mongodb] Fix MongoDB credential encoding for spaces Oct 12, 2026
@LuanaMihailescu

Copy link
Copy Markdown
Author

Hi @leonardBang

This PR fixes the credential encoding issue described in FLINK-40957 and includes a test case for the reported behavior.

Could you please review it when you have time?

Thanks!

@LuanaMihailescu

Copy link
Copy Markdown
Author

Hi @lvyanquan

This PR fixes the credential encoding issue described in FLINK-40957 and includes a test case for the reported behavior.

Could you please review it when you have time?

Thanks!

@sd4324530 sd4324530 left a comment

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.

Hi, I left some comments. Currently, CI hasn't passed. You can refer to the format of other files in the project and make corresponding modifications. It would be even better if you could successfully compile locally first.

@yuxiqian yuxiqian 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 your contribution! Just left some comments.

@yuxiqian

Copy link
Copy Markdown
Member

CI is still failing, please run mvn spotless:apply to fix code style violations.

Luana added 2 commits October 26, 2026 17:45
…in buildConnectionString

Per review feedback, revert MongoDBEnvelope#encodeValue() to its original,
generic percent-encoding behavior, since it is not specific to MongoDB
credentials and other callers could be affected by changing it.

Move the space ('+' -> '%20') correction into a new private
MongoUtils#encodeCredential() helper, applied only to username/password
when building the connection string in buildConnectionString(). Replace
MongoDBEnvelopeTest (which tested the reverted behavior) with MongoUtilsTest,
covering buildConnectionString directly.
…taining spaces

Add end-to-end tests to MongoDBParallelSourceITCase verifying that the
MongoDB CDC source authenticates and reads data successfully when the
username and/or password contain spaces, per review feedback.
@LuanaMihailescu

Copy link
Copy Markdown
Author

Thanks for the feedback.

I've updated the implementation based on the review comments, added unit and integration tests, and addressed the Spotless formatting issues.

Could someone please re-run the CI checks when possible?

@yuxiqian @sd4324530

Thanks!

@Jiabao-Sun Jiabao-Sun left a comment

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.

Thanks @LuanaMihailescu for this fix.
Could you help verify if other special characters like ~ and * would have the same problem?

@LuanaMihailescu

Copy link
Copy Markdown
Author

Hi @Jiabao-Sun, I've checked ~ and * in MongoDB credentials. They don’t have the same issue as spaces: neither is converted to + by the encoding. I also added a unit test covering both characters, and it passes.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants