Update connection-parameters.js

The current connection url handling fails when the password contains
encoded special characters: After the encodeURI, the special
characters from the password are double encoded, and the password is
rejected by postgres.

Proposed fix handles one level of double encoding, and while it
might break compatibility with passwords like "asdfg%77fgh" (which
would've been escaped to asdfg%2577fgh before this patch), I
strongly feel that maintaining backwards compatibility is in this
case less important than following standards and discouraging bad
coding practices.
This commit is contained in:
za-creature 2013-04-11 19:57:03 +03:00
parent b33c266734
commit c666b20287

View File

@ -17,7 +17,8 @@ var parse = function(str) {
return { host: str };
}
// url parse expects spaces encoded as %20
str = encodeURI(str);
// however, we don't want to double-encode
str = encodeURI(str).replace(/\%25/g, "%");
var result = url.parse(str);
var config = {};
config.host = result.hostname;