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: decode encoded value from urlParts.pathname for database option #14963

Merged
merged 8 commits into from Sep 14, 2022
3 changes: 2 additions & 1 deletion src/utils/url.ts
Expand Up @@ -26,7 +26,8 @@ export function parseConnectionString(connectionString: string): Options {
}

if (urlParts.pathname) {
options.database = urlParts.pathname.replace(/^\//, '');
// decode the URI component from urlParts.pathname value
options.database = decodeURIComponent(urlParts.pathname.replace(/^\//, ''));
}

if (urlParts.port) {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/utils/utils.test.ts
Expand Up @@ -154,4 +154,16 @@ describe(getTestDialectTeaser('Utils'), () => {
});
});
});

describe('url', () => {
it('should return the correct options after parsed', () => {
const options = Utils.parseConnectionString('pg://wpx%20ss:wpx%20ss@21.77.77:4001/database ss');
expect(options.dialect).to.equal('pg');
expect(options.host).to.equal('21.77.77');
expect(options.port).to.equal('4001');
expect(options.database).to.equal('database ss');
expect(options.username).to.equal('wpx ss');
expect(options.password).to.equal('wpx ss');
});
});
});