Skip to content
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

fix: net/url in newer versions of Go (>1.9.4) reject with "invalid userinfo" when there are special characters in the connection string #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/db-migrate-function/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ const buildConnectionString = (
): string => {
const { username, password, host, port, engine } = databaseSecret;

const encodedPassword = encodeURIComponent(password);
const encodedUsername = encodeURIComponent(username);

switch (engine) {
case 'mysql':
return `mysql://${username}:${password}@tcp(${host}:${port})/${dbName}`;
return `mysql://${encodedUsername}:${encodedPassword}@tcp(${host}:${port})/${dbName}`;
case 'postgres':
return `postgres://${username}:${password}@${host}:${port}/${dbName}`;
return `postgres://${encodedUsername}:${encodedPassword}@${host}:${port}/${dbName}`;
default:
throw new Error(
`Unsupported (or not yet implemented) database engine for migrate target: ${databaseSecret.engine}`,
Expand Down
Loading