From f90d31be7659b3541919a42ebb0534549e376c8e Mon Sep 17 00:00:00 2001 From: zhangyangyu Date: Sun, 6 Aug 2023 01:24:41 +0800 Subject: [PATCH 1/3] QueryUnescape DSN ConnectionAttribute value --- driver_test.go | 20 +++++++++++++++++--- dsn.go | 6 +++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/driver_test.go b/driver_test.go index 2748870b..500080dc 100644 --- a/driver_test.go +++ b/driver_test.go @@ -3367,9 +3367,12 @@ func TestConnectionAttributes(t *testing.T) { attr1 := "attr1" value1 := "value1" - attr2 := "foo" - value2 := "boo" - dsn += fmt.Sprintf("&connectionAttributes=%s:%s,%s:%s", attr1, value1, attr2, value2) + attr2 := "fo/o" + value2 := "bo/o" + dsn += fmt.Sprintf( + "&connectionAttributes=%s:%s,%s:%s", + attr1, value1, url.QueryEscape(attr2), url.QueryEscape(value2), + ) var db *sql.DB if _, err := ParseDSN(dsn); err != errInvalidDSNUnsafeCollation { @@ -3395,6 +3398,17 @@ func TestConnectionAttributes(t *testing.T) { } rows.Close() + rows = dbt.mustQuery(queryString, attr1) + if rows.Next() { + rows.Scan(&attrValue) + if attrValue != value1 { + dbt.Errorf("expected %q, got %q", value1, attrValue) + } + } else { + dbt.Errorf("no data") + } + rows.Close() + rows = dbt.mustQuery(queryString, attr2) if rows.Next() { rows.Scan(&attrValue) diff --git a/dsn.go b/dsn.go index 380ca957..3b4e19ac 100644 --- a/dsn.go +++ b/dsn.go @@ -569,7 +569,11 @@ func parseDSNParams(cfg *Config, params string) (err error) { // Connection attributes case "connectionAttributes": - cfg.ConnectionAttributes = value + connectionAttributes, err := url.QueryUnescape(value) + if err != nil { + return fmt.Errorf("invalid connectionAttributes value: %v", err) + } + cfg.ConnectionAttributes = connectionAttributes default: // lazy init From 13505f935f80351f0795864144e1bd5851ac5306 Mon Sep 17 00:00:00 2001 From: zhangyangyu Date: Sun, 6 Aug 2023 01:30:31 +0800 Subject: [PATCH 2/3] add authors --- AUTHORS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index 29e08b0c..ddfaeb04 100644 --- a/AUTHORS +++ b/AUTHORS @@ -108,6 +108,7 @@ Xiangyu Hu Xiaobing Jiang Xiuming Chen Xuehong Chan +Zhang Xiang Zhenye Xie Zhixin Wen Ziheng Lyu @@ -126,6 +127,7 @@ InfoSum Ltd. Keybase Inc. Multiplay Ltd. Percona LLC +PingCAP Inc. Pivotal Inc. Stripe Inc. Zendesk Inc. From a2624c8c6d681216be86275c993c2717cd846bea Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Thu, 19 Oct 2023 03:23:45 -0500 Subject: [PATCH 3/3] Update driver_test.go --- driver_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/driver_test.go b/driver_test.go index 500080dc..21128397 100644 --- a/driver_test.go +++ b/driver_test.go @@ -3369,10 +3369,8 @@ func TestConnectionAttributes(t *testing.T) { value1 := "value1" attr2 := "fo/o" value2 := "bo/o" - dsn += fmt.Sprintf( - "&connectionAttributes=%s:%s,%s:%s", - attr1, value1, url.QueryEscape(attr2), url.QueryEscape(value2), - ) + dsn += "&connectionAttributes=" + url.QueryEscape(fmt.Sprintf("%s:%s,%s:%s", attr1, value1, attr2, value2)) + var db *sql.DB if _, err := ParseDSN(dsn); err != errInvalidDSNUnsafeCollation {