Skip to content

Connection string - passwords with : or ? are not encoded #3557

@Idlesome

Description

@Idlesome

When I have a connection string with special characters such as:

postgresql://username:pass?word:3$@my-database-host.com:5432/dbname

I get this error:

TypeError: Cannot read properties of undefined (reading 'searchParams')

This is because the ? is determined to be the end of the URL (it's expecting something like ?sslmode=require at the end of the string).

Essentially the URL has not been encoded correctly. To resolve this, you can URL encode your password - so this will work:

postgresql://username:pass%3Fword%3A3%24@my-database-host.com:5432/dbname

However, if you're passing your connection string as a secret without having encoded it ahead of time, you'd have to manually extract the password and apply this encoding.

I'm posting this mainly to help others who may run into issue, especially since it's not obvious from the error what the problem is - but perhaps we could resolve this by automatically encoding the password, or otherwise throwing an "invalid connection string" error if the password is not encoded properly?

I may be wrong, but I think Drizzle's pg client seems to work "out of the box" with this type of connection string.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions