Skip to content

Commit fe573ad

Browse files
authored
fix: add decodeuricomponent to parse uri encoded special characters in host, username, password and datbase keys (#2277)
1 parent 72b2535 commit fe573ad

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

lib/connection_config.js

+4-4
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

+31-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,36 @@ 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
);
52+
53+
assert.strictEqual(
54+
ConnectionConfig.parseUrl(
55+
String.raw`fml://user%40test.com:pass!%40%24%25%5E%26*()word%3A@www.example.com/database`,
56+
).user,
57+
'user@test.com',
58+
);
59+
60+
assert.strictEqual(
61+
ConnectionConfig.parseUrl(
62+
String.raw`fml://test:pass@wordA@fe80%3A3438%3A7667%3A5c77%3Ace27%2518/database`,
63+
).host,
64+
'fe80:3438:7667:5c77:ce27%18',
65+
);
66+
67+
assert.strictEqual(
68+
ConnectionConfig.parseUrl(
69+
String.raw`fml://test:pass@wordA@www.example.com/database`,
70+
).host,
71+
'www.example.com',
72+
);
73+
74+
assert.strictEqual(
75+
ConnectionConfig.parseUrl(
76+
String.raw`fml://test:pass@wordA@www.example.com/database%24`,
77+
).database,
78+
'database$',
79+
);
80+

0 commit comments

Comments
 (0)