From 37980127edfb00edd1ba2eb397a33fdea2828828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 5 Oct 2023 11:44:35 +0300 Subject: [PATCH] use strings.Cut (#1486) --- connector.go | 9 ++++----- dsn.go | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/connector.go b/connector.go index 7e0b16734..ba3be71e7 100644 --- a/connector.go +++ b/connector.go @@ -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) diff --git a/dsn.go b/dsn.go index f5b184e3f..50c7ec413 100644 --- a/dsn.go +++ b/dsn.go @@ -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 @@ -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 } }