From ffcbc82ce8e7d76e4a225a8d4805ea8cf6fab5b1 Mon Sep 17 00:00:00 2001 From: ramya-bangera Date: Wed, 9 Oct 2024 12:23:11 +0530 Subject: [PATCH] Fix the password parsing issue Queryescape user and password only if it is not already escaped. --- internal/cli/main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/cli/main.go b/internal/cli/main.go index e1d21934d..48873d4b3 100644 --- a/internal/cli/main.go +++ b/internal/cli/main.go @@ -67,10 +67,20 @@ func printUsageAndExit() { func dbMakeConnectionString(driver, user, password, address, name, ssl string) string { return fmt.Sprintf("%s://%s:%s@%s/%s?sslmode=%s", - driver, url.QueryEscape(user), url.QueryEscape(password), address, name, ssl, + driver, EscapeIfNeeded(user), EscapeIfNeeded(password), address, name, ssl, ) } +func EscapeIfNeeded(str string) string { + unescapedStr, err := url.QueryUnescape(str) + if err != nil || unescapedStr == str { + // If the str is already unescaped or an error occurred, escape it + return url.QueryEscape(str) + } + // If the str was successfully unescaped, return it as is + return str +} + // Main function of a cli application. It is public for backwards compatibility with `cli` package func Main(version string) { help := viper.GetBool("help")