Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: password contains @ #113

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading