This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch release-v0.16
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v0.16 by this push:
     new 2d4c5e70f fix: GORM init fix to allow special characters in connection 
string (#4665)
2d4c5e70f is described below

commit 2d4c5e70f8b1f83356651ef2816163eeaf888e59
Author: Keon Amini <[email protected]>
AuthorDate: Tue Mar 14 22:24:01 2023 -0500

    fix: GORM init fix to allow special characters in connection string (#4665)
---
 backend/core/runner/db.go | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/backend/core/runner/db.go b/backend/core/runner/db.go
index b2d4001d5..b5ef01bb0 100644
--- a/backend/core/runner/db.go
+++ b/backend/core/runner/db.go
@@ -85,7 +85,7 @@ func NewGormDbEx(configReader config.ConfigReader, logger 
log.Logger, sessionCon
        var db *gorm.DB
        switch strings.ToLower(u.Scheme) {
        case "mysql":
-               dbUrl = fmt.Sprintf("%s@tcp(%s)%s?%s", u.User.String(), u.Host, 
u.Path, u.RawQuery)
+               dbUrl = fmt.Sprintf("%s@tcp(%s)%s?%s", getUserString(u), 
u.Host, u.Path, u.RawQuery)
                db, err = gorm.Open(mysql.Open(dbUrl), dbConfig)
        case "postgresql", "postgres", "pg":
                db, err = gorm.Open(postgres.Open(dbUrl), dbConfig)
@@ -105,3 +105,12 @@ func NewGormDbEx(configReader config.ConfigReader, logger 
log.Logger, sessionCon
 
        return db, errors.Convert(err)
 }
+
+func getUserString(u *url.URL) string {
+       userString := u.User.Username()
+       password, ok := u.User.Password()
+       if ok {
+               userString = fmt.Sprintf("%s:%s", userString, password)
+       }
+       return userString
+}

Reply via email to