mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: escape special characters in postgres password (#16510)
Fixes: https://github.com/coder/coder/issues/16319 This PR modifies existing escaping logic for special characters in Postgres password, so it does fail on edge cases like `#` or `$` when parser recognizes as invalid port.
This commit is contained in:
@@ -351,13 +351,23 @@ func TestEscapePostgresURLUserInfo(t *testing.T) {
|
||||
output: "",
|
||||
err: xerrors.New("parse postgres url: parse \"postgres://local host:5432/coder\": invalid character \" \" in host name"),
|
||||
},
|
||||
{
|
||||
input: "postgres://coder:co?der@localhost:5432/coder",
|
||||
output: "postgres://coder:co%3Fder@localhost:5432/coder",
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
input: "postgres://coder:co#der@localhost:5432/coder",
|
||||
output: "postgres://coder:co%23der@localhost:5432/coder",
|
||||
err: nil,
|
||||
},
|
||||
}
|
||||
for _, tc := range testcases {
|
||||
tc := tc
|
||||
t.Run(tc.input, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
o, err := escapePostgresURLUserInfo(tc.input)
|
||||
require.Equal(t, tc.output, o)
|
||||
assert.Equal(t, tc.output, o)
|
||||
if tc.err != nil {
|
||||
require.Error(t, err)
|
||||
require.EqualValues(t, tc.err.Error(), err.Error())
|
||||
|
||||
Reference in New Issue
Block a user