Skip to content

Commit

Permalink
use strings.Cut (#1486)
Browse files Browse the repository at this point in the history
  • Loading branch information
scop authored Oct 5, 2023
1 parent e5a2abc commit 3798012
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ func encodeConnectionAttributes(textAttributes string) string {

// user-defined connection attributes
for _, connAttr := range strings.Split(textAttributes, ",") {
attr := strings.SplitN(connAttr, ":", 2)
if len(attr) != 2 {
k, v, found := strings.Cut(connAttr, ":")
if !found {
continue
}
for _, v := range attr {
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, v)
}
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, k)
connAttrsBuf = appendLengthEncodedString(connAttrsBuf, v)
}

return string(connAttrsBuf)
Expand Down
8 changes: 4 additions & 4 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,13 @@ func ParseDSN(dsn string) (cfg *Config, err error) {
// Values must be url.QueryEscape'ed
func parseDSNParams(cfg *Config, params string) (err error) {
for _, v := range strings.Split(params, "&") {
param := strings.SplitN(v, "=", 2)
if len(param) != 2 {
key, value, found := strings.Cut(v, "=")
if !found {
continue
}

// cfg params
switch value := param[1]; param[0] {
switch key {
// Disable INFILE allowlist / enable all files
case "allowAllFiles":
var isBool bool
Expand Down Expand Up @@ -577,7 +577,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
cfg.Params = make(map[string]string)
}

if cfg.Params[param[0]], err = url.QueryUnescape(value); err != nil {
if cfg.Params[key], err = url.QueryUnescape(value); err != nil {
return
}
}
Expand Down

0 comments on commit 3798012

Please sign in to comment.