Skip to content

Commit

Permalink
Fix the password parsing issue
Browse files Browse the repository at this point in the history
Queryescape user and password only if it is not already escaped.
  • Loading branch information
ramya-bangera committed Oct 9, 2024
1 parent 13318b2 commit 4591af6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 4591af6

Please sign in to comment.