fix: escape credentials and options when rebuilding the MongoDB URI - #41
Merged
Merged
Conversation
SQLAlchemy percent-decodes username, password and query values when parsing the URL. create_connect_args reassembled the MongoDB URI from those decoded values without re-escaping them, so a password containing a reserved character such as @ broke pymongo's userinfo parsing even when the user had correctly encoded it as %40. Re-escape credentials and query keys/values with quote_plus, and emit repeated query keys once per value instead of stringifying the tuple.
msyavuz
force-pushed
the
msyavuz/fix/escape-uri-credentials
branch
from
September 7, 2026 12:44
d11600c to
573d425
Compare
Owner
|
@msyavuz Thank you for the contribution. This change has been released through v0.7.4. |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
create_connect_argsrebuilt the MongoDB URI fromurl.username/url.password/url.query, which SQLAlchemy has already percent-decoded. A password with a reserved character (e.g.@) was re-injected unescaped, so pymongo failed with "Username and password must be escaped according to RFC 3986" even when the user had correctly encoded it as%40.Changes
quote_pluswhen reassembling the URI.readPreferenceTags) once per value instead of stringifying SQLAlchemy's tuple.pymongo.uri_parser.parse_uri), username-only, escaped option values, and repeated keys.Repro
mongodb://user:p%40ssword@host/db→ dialect previously producedmongodb://user:p@ssword@host/db; now producesmongodb://user:p%40ssword@host/db.