fix: URL decode database name when parsing connection url #3593
+5
−1
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.
The problem
Connecting to databases with non-standard characters in the db name fails.
Fails with
database "test%20db" does not exist
Creating a connection configuration, and then setting the db name explicitly, fixes the issue:
Additionally, setting the db name with a query parameter also fixes the problem:
Background
When parsing a connection string, the various parts are url decoded before being stored in the connection configuration struct.
The one exception is the database name.
When we get the name from the
dbname
query param, it seems the values are decoded.When building back a URL, it seems we rely on the behavior of the
set_path
path method which will encode the string if needed, (if we passed the name using the dbname query param), or leave it as is if already percent encoded (if we passed it using the url path)However, it looks like the
establish
method does not handle getting a url encoded database name, and sends it as-is. Hence our problem.Fix
URL decode the db name when extracted from the path of a connection string