From b502920b0bb888986f700c31822619df85d5ae02 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Fri, 17 Nov 2023 13:30:58 -0500 Subject: [PATCH] Revise buildURL function The RawQuery field would not be properly populated in the old implementation. Has been fixed by calling the Parse function at the end. --- engine/storage_utils.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/engine/storage_utils.go b/engine/storage_utils.go index 02f9cc508..e4bc4d597 100644 --- a/engine/storage_utils.go +++ b/engine/storage_utils.go @@ -22,7 +22,6 @@ import ( "fmt" "net" "net/url" - "path" "strconv" "strings" "time" @@ -85,21 +84,19 @@ func NewStorDBConn(dbType, host, port, name, user, pass, marshaler string, } func buildURL(scheme, host, port, db, user, pass string) (*url.URL, error) { - u, err := url.Parse("//" + host) - if err != nil { - return nil, err + rawURL := scheme + "://" + if user != "" && pass != "" { + rawURL += url.UserPassword(user, pass).String() + "@" } if port != "0" { - u.Host = net.JoinHostPort(u.Host, port) - } - if user != "" && pass != "" { - u.User = url.UserPassword(user, pass) + rawURL += net.JoinHostPort(host, port) + } else { + rawURL += host } if db != "" { - u.Path = path.Join(u.Path, db) + rawURL += "/" + db } - u.Scheme = scheme - return u, nil + return url.Parse(rawURL) } // SMCost stores one Cost coming from SM