Skip to content

Commit b2e2ccb

Browse files
authored
QueryUnescape DSN ConnectionAttribute value (#1470)
1 parent 18b74e4 commit b2e2ccb

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

Diff for: AUTHORS

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Xiangyu Hu <xiangyu.hu at outlook.com>
109109
Xiaobing Jiang <s7v7nislands at gmail.com>
110110
Xiuming Chen <cc at cxm.cc>
111111
Xuehong Chan <chanxuehong at gmail.com>
112+
Zhang Xiang <angwerzx at 126.com>
112113
Zhenye Xie <xiezhenye at gmail.com>
113114
Zhixin Wen <john.wenzhixin at gmail.com>
114115
Ziheng Lyu <zihenglv at gmail.com>
@@ -127,6 +128,7 @@ InfoSum Ltd.
127128
Keybase Inc.
128129
Multiplay Ltd.
129130
Percona LLC
131+
PingCAP Inc.
130132
Pivotal Inc.
131133
Stripe Inc.
132134
Zendesk Inc.

Diff for: driver_test.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -3379,9 +3379,10 @@ func TestConnectionAttributes(t *testing.T) {
33793379

33803380
attr1 := "attr1"
33813381
value1 := "value1"
3382-
attr2 := "foo"
3383-
value2 := "boo"
3384-
dsn += fmt.Sprintf("&connectionAttributes=%s:%s,%s:%s", attr1, value1, attr2, value2)
3382+
attr2 := "fo/o"
3383+
value2 := "bo/o"
3384+
dsn += "&connectionAttributes=" + url.QueryEscape(fmt.Sprintf("%s:%s,%s:%s", attr1, value1, attr2, value2))
3385+
33853386

33863387
var db *sql.DB
33873388
if _, err := ParseDSN(dsn); err != errInvalidDSNUnsafeCollation {
@@ -3407,6 +3408,17 @@ func TestConnectionAttributes(t *testing.T) {
34073408
}
34083409
rows.Close()
34093410

3411+
rows = dbt.mustQuery(queryString, attr1)
3412+
if rows.Next() {
3413+
rows.Scan(&attrValue)
3414+
if attrValue != value1 {
3415+
dbt.Errorf("expected %q, got %q", value1, attrValue)
3416+
}
3417+
} else {
3418+
dbt.Errorf("no data")
3419+
}
3420+
rows.Close()
3421+
34103422
rows = dbt.mustQuery(queryString, attr2)
34113423
if rows.Next() {
34123424
rows.Scan(&attrValue)

Diff for: dsn.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,11 @@ func parseDSNParams(cfg *Config, params string) (err error) {
569569

570570
// Connection attributes
571571
case "connectionAttributes":
572-
cfg.ConnectionAttributes = value
572+
connectionAttributes, err := url.QueryUnescape(value)
573+
if err != nil {
574+
return fmt.Errorf("invalid connectionAttributes value: %v", err)
575+
}
576+
cfg.ConnectionAttributes = connectionAttributes
573577

574578
default:
575579
// lazy init

0 commit comments

Comments
 (0)