8000 Implement a permissive decodeURIComponent · mysqljs/mysql@6725ac8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6725ac8

Browse files
committed
Implement a permissive decodeURIComponent
1 parent d1b2511 commit 6725ac8

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/ConnectionConfig.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,7 @@ ConnectionConfig.parseUrl = function(url) {
187187

188188
if (typeof url.username == 'string') {
189189
options.user = url.username;
190-
try {
191-
options.password = decodeURIComponent(url.password);
192-
} catch (e) {
193-
options.password = url.password;
194-
}
190+
options.password = decodeUriComponent(url.password);
195191
} else if (url.auth) {
196192
var auth = url.auth.split(':');
197193
options.user = auth.shift();
@@ -224,3 +220,13 @@ ConnectionConfig.parseUrl = function(url) {
224220

225221
return options;
226222
};
223+
224+
function decodeUriComponent(str) {
225+
return str.replace(/\%([a-f0-9]{2})/ig, function (_, hex) {
226+
try {
227+
return String.fromCharCode(parseInt(hex, 16));
228+
} catch (e) {
229+
return _;
230+
}
231+
});
232+
}

0 commit comments

Comments
 (0)
0