Skip to content

Commit

Permalink
Fix for special characters in MongoDB password.
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantkhandelwal committed Jan 13, 2023
1 parent 071eb53 commit 430a73a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/models/dbconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func NewDBConnection(projectID string, name string, dbtype string, dbscheme, dbh
if !utils.ContainsString([]string{"mongodb", "mongodb+srv"}, dbscheme) {
return nil, errors.New("invalid dbscheme")
}

dbpassword = utils.ParsePwd(dbpassword)

} else {
return nil, errors.New("dbtype is not correct")
}
Expand Down
14 changes: 14 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ func RandString(n int) string {
return *(*string)(unsafe.Pointer(&b))
}

// Parse special characters in HexASCII
func ParsePwd(p string) string {
sc := "~!@#$%^&*()_+{}|<>:?"
var s string
for _, v := range p {
if strings.Contains(sc, string(v)) {
s += "%" + hex.EncodeToString([]byte(string(v)))
} else {
s += string(v)
}
}
return s
}

func FileExtensionFromPath(path string) string {
if strs := strings.Split(path, "."); true {
slen := len(strs)
Expand Down

0 comments on commit 430a73a

Please sign in to comment.