From 6725ac8be611cd2840bb0bc362c651368c261619 Mon Sep 17 00:00:00 2001 From: Diogo Resende Date: Tue, 21 Nov 2023 16:12:42 +0000 Subject: [PATCH] Implement a permissive decodeURIComponent --- lib/ConnectionConfig.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ConnectionConfig.js b/lib/ConnectionConfig.js index 0e7a4480..a6f8fa78 100644 --- a/lib/ConnectionConfig.js +++ b/lib/ConnectionConfig.js @@ -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(); @@ -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 _; + } + }); +}