Skip to content

Commit 9c20fbe

Browse files
committed
fix: add decodeuricomponent to parse uri encoded special characters in host, username, password and datbase keys
1 parent 1aec4fd commit 9c20fbe

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/connection_config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ class ConnectionConfig {
260260
static parseUrl(url) {
261261
const parsedUrl = new URL(url);
262262
const options = {
263-
host: parsedUrl.hostname,
263+
host: decodeURIComponent(parsedUrl.hostname),
264264
port: parseInt(parsedUrl.port, 10),
265-
database: parsedUrl.pathname.slice(1),
266-
user: parsedUrl.username,
267-
password: parsedUrl.password
265+
database: decodeURIComponent(parsedUrl.pathname.slice(1)),
266+
user: decodeURIComponent(parsedUrl.username),
267+
password: decodeURIComponent(parsedUrl.password),
268268
};
269269
parsedUrl.searchParams.forEach((value, key) => {
270270
try {

test/unit/connection/test-connection_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ assert.doesNotThrow(() => {
4545

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

0 commit comments

Comments
 (0)