Skip to content

Commit

Permalink
Implement a permissive decodeURIComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
dresende committed Nov 21, 2023
1 parent d1b2511 commit 6725ac8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/ConnectionConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,7 @@ ConnectionConfig.parseUrl = function(url) {

if (typeof url.username == 'string') {
options.user = url.username;
try {
options.password = decodeURIComponent(url.password);
} catch (e) {
options.password = url.password;
}
options.password = decodeUriComponent(url.password);
} else if (url.auth) {
var auth = url.auth.split(':');
options.user = auth.shift();
Expand Down Expand Up @@ -224,3 +220,13 @@ ConnectionConfig.parseUrl = function(url) {

return options;
};

function decodeUriComponent(str) {
return str.replace(/\%([a-f0-9]{2})/ig, function (_, hex) {
try {
return String.fromCharCode(parseInt(hex, 16));
} catch (e) {
return _;
}
});
}

0 comments on commit 6725ac8

Please sign in to comment.