Skip to content

fix wrong urllib parse function being used to percent encode usernames and passwords, where before spaces would be incorrectly encoded to '+' instead of '%20' which is behaviour for a different usecase #1186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

heymoonman
Copy link

The example given for percent-encoding usernames and passwords for a MongoDB URI first mentions .quote() should be used, but proceeds to incorrectly use .quote_plus(), changing spaces to plus signs instead of their percent encoding equivalent.

The example should use .quote() to be clear and exemplify proper use.

…s and passwords, where before spaces would be incorrectly encoded to '+' instead of '%20' which is behaviour for a different usecase
@blink1073
Copy link
Member

Hi @M-Moon, these examples were changed to handle the case where the username or password contains an unescaped / character, which would get interpreted as the database name. https://jira.mongodb.org/browse/PYTHON-2973. I think the right thing to do is change the examples to use quote(..., safe='')

@heymoonman
Copy link
Author

Thanks for the response @blink1073, this makes sense. I was not aware of the issue so thanks for letting me know.

@ShaneHarvey
Copy link
Member

In this case the code example is correct but the paragraph is wrong. It should say:

Username and password must be percent-escaped with
:py:func:`urllib.parse.quote_plus`, to be used in a MongoDB URI.

@ShaneHarvey
Copy link
Member

@M-Moon thank you for reporting this, I've fixed it in #1193!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants