diff --git a/AUTHORS b/AUTHORS index 29e08b0ca..ddfaeb049 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. diff --git a/driver_test.go b/driver_test.go index 2748870b7..21128397e 100644 --- a/driver_test.go +++ b/driver_test.go @@ -3367,9 +3367,10 @@ 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 += "&connectionAttributes=" + url.QueryEscape(fmt.Sprintf("%s:%s,%s:%s", attr1, value1, attr2, value2)) + var db *sql.DB if _, err := ParseDSN(dsn); err != errInvalidDSNUnsafeCollation { @@ -3395,6 +3396,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 380ca9570..3b4e19ac3 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