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: add decodeuricomponent to parse uri encoded special characters in host, username, password and datbase keys #2277

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions lib/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ class ConnectionConfig {
static parseUrl(url) {
const parsedUrl = new URL(url);
const options = {
host: parsedUrl.hostname,
host: decodeURIComponent(parsedUrl.hostname),
port: parseInt(parsedUrl.port, 10),
database: parsedUrl.pathname.slice(1),
user: parsedUrl.username,
password: parsedUrl.password
database: decodeURIComponent(parsedUrl.pathname.slice(1)),
user: decodeURIComponent(parsedUrl.username),
password: decodeURIComponent(parsedUrl.password),
};
parsedUrl.searchParams.forEach((value, key) => {
try {
Expand Down
33 changes: 31 additions & 2 deletions test/unit/connection/test-connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,36 @@ assert.doesNotThrow(() => {

assert.strictEqual(
ConnectionConfig.parseUrl(
String.raw`fml://test:pass!@$%^&*()\word:@www.example.com/database`
String.raw`fml://test:pass!%40%24%25%5E%26*()word%3A@www.example.com/database`,
).password,
'pass!%40$%%5E&*()%5Cword%3A'
'pass!@$%^&*()word:',
);

assert.strictEqual(
ConnectionConfig.parseUrl(
String.raw`fml://user%40test.com:pass!%40%24%25%5E%26*()word%[email protected]/database`,
).user,
'[email protected]',
);

assert.strictEqual(
ConnectionConfig.parseUrl(
String.raw`fml://test:pass@wordA@fe80%3A3438%3A7667%3A5c77%3Ace27%2518/database`,
).host,
'fe80:3438:7667:5c77:ce27%18',
);

assert.strictEqual(
ConnectionConfig.parseUrl(
String.raw`fml://test:pass@[email protected]/database`,
).host,
'www.example.com',
);

assert.strictEqual(
ConnectionConfig.parseUrl(
String.raw`fml://test:pass@[email protected]/database%24`,
).database,
'database$',
);

Loading