Repository navigation
Conversation
URLSearchParams decodes query strings as form data, so a + in a query value became a space: postgres://h/d?password=a+b gave the password 'a b', while libpq only percent-decodes and uses 'a+b'. Read the query parameters with + escaped first. A space can still be written as %20.
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.
parse()reads query parameters withURLSearchParams, which decodes them as form data, so a+in a value becomes a space:libpq only percent-decodes URI values (
conninfo_uri_decodeinsrc/interfaces/libpq/fe-connect.ccopies every character other than a%XXescape as is), so for libpq the password inpostgres://h/d?password=a+bisa+b. The README also says the other query parameters are "preserved intact". This affects every generic query parameter (user,password,application_name,options, ...), so a password with a+given as a query parameter fails to authenticate.The fix escapes
+before building theURLSearchParamsfor the generic parameters, so values are only percent-decoded. A space can still be written as%20(or%2Bfor an explicit plus, as before). Thesocket:branch, where the README saysdbis urlencoded, is unchanged.Compatibility: this changes the result for connection strings that use
+to mean a space in a query value: they now get a literal+, as libpq does. If you would rather ship this in a major version or behind an option, I can adjust it.Tests: a new case in
test/parse.tschecksapplication_name,user,passwordandoptionswith+and with%2B/%20. It fails before the change ('a b'instead of'a+b') and passes after it. Inpackages/pg-connection-string, mocha passes (81 tests) with 100% statement/branch/function/line coverage under nyc, and eslint (repository config with prettier) is clean on both files. I did not run the other packages' tests.