Skip to content

Commit f90d31b

Browse files
committed
QueryUnescape DSN ConnectionAttribute value
1 parent 2c81c69 commit f90d31b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Diff for: driver_test.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -3367,9 +3367,12 @@ func TestConnectionAttributes(t *testing.T) {
33673367

33683368
attr1 := "attr1"
33693369
value1 := "value1"
3370-
attr2 := "foo"
3371-
value2 := "boo"
3372-
dsn += fmt.Sprintf("&connectionAttributes=%s:%s,%s:%s", attr1, value1, attr2, value2)
3370+
attr2 := "fo/o"
3371+
value2 := "bo/o"
3372+
dsn += fmt.Sprintf(
3373+
"&connectionAttributes=%s:%s,%s:%s",
3374+
attr1, value1, url.QueryEscape(attr2), url.QueryEscape(value2),
3375+
)
33733376

33743377
var db *sql.DB
33753378
if _, err := ParseDSN(dsn); err != errInvalidDSNUnsafeCollation {
@@ -3395,6 +3398,17 @@ func TestConnectionAttributes(t *testing.T) {
33953398
}
33963399
rows.Close()
33973400

3401+
rows = dbt.mustQuery(queryString, attr1)
3402+
if rows.Next() {
3403+
rows.Scan(&attrValue)
3404+
if attrValue != value1 {
3405+
dbt.Errorf("expected %q, got %q", value1, attrValue)
3406+
}
3407+
} else {
3408+
dbt.Errorf("no data")
3409+
}
3410+
rows.Close()
3411+
33983412
rows = dbt.mustQuery(queryString, attr2)
33993413
if rows.Next() {
34003414
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)