Skip to content

Commit

Permalink
Merge pull request #113 from bingocmp/hotfix/trans-sqlachemy-url
Browse files Browse the repository at this point in the history
fix: password contains @
  • Loading branch information
swordqiu authored Jan 19, 2024
2 parents 64f11f7 + 7e8328e commit 0486a12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,15 @@ func TransSQLAchemyURL(pySQLSrc string) (dialect, ret string, err error) {
return dialect, pySQLSrc, nil
}

r := regexp.MustCompile(`[/@:]+`)
strs := r.Split(pySQLSrc, -1)
lastAtIndex := strings.LastIndex(pySQLSrc, "@")
firstPart := pySQLSrc[:lastAtIndex]
secondPart := pySQLSrc[lastAtIndex+1:]

r := regexp.MustCompile(`[/:]+`)
firstPartArr := r.Split(firstPart, -1)
secondPartArr := r.Split(secondPart, -1)

strs := append(firstPartArr, secondPartArr...)
if len(strs) != 6 {
err = fmt.Errorf("Incorrect mysql connection url: %s", pySQLSrc)
return
Expand Down
5 changes: 5 additions & 0 deletions utils/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,11 @@ func TestTransSQLAchemyURL(t *testing.T) {
args: args{"root:root@127.0.0.1:3306/mclouds?charset=utf8"},
wantRet: "root:root@127.0.0.1:3306/mclouds?charset=utf8",
wantErr: false,
}, {
name: "supported at",
args: args{"mysql+pymysql://root:5bTcx^@Peh4nj3H7@127.0.0.1:3306/mclouds?charset=utf8"},
wantRet: "root:5bTcx^@Peh4nj3H7@tcp(127.0.0.1:3306)/mclouds?charset=utf8&parseTime=True",
wantErr: false,
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 0486a12

Please # to comment.