Skip to content

Commit

Permalink
fix: add decodeuricomponent to parse uri encoded special characters i…
Browse files Browse the repository at this point in the history
…n host, username, password and datbase keys (#2277)
  • Loading branch information
samarpanB authored Nov 22, 2023
1 parent 72b2535 commit fe573ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
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%3A@www.example.com/database`,
).user,
'user@test.com',
);

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@wordA@www.example.com/database`,
).host,
'www.example.com',
);

assert.strictEqual(
ConnectionConfig.parseUrl(
String.raw`fml://test:pass@wordA@www.example.com/database%24`,
).database,
'database$',
);

0 comments on commit fe573ad

Please sign in to comment.