Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryUnescape DSN ConnectionAttribute value #1470

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Xiangyu Hu <xiangyu.hu at outlook.com>
Xiaobing Jiang <s7v7nislands at gmail.com>
Xiuming Chen <cc at cxm.cc>
Xuehong Chan <chanxuehong at gmail.com>
Zhang Xiang <angwerzx at 126.com>
Zhenye Xie <xiezhenye at gmail.com>
Zhixin Wen <john.wenzhixin at gmail.com>
Ziheng Lyu <zihenglv at gmail.com>
Expand All @@ -126,6 +127,7 @@ InfoSum Ltd.
Keybase Inc.
Multiplay Ltd.
Percona LLC
PingCAP Inc.
Pivotal Inc.
Stripe Inc.
Zendesk Inc.
Expand Down
18 changes: 15 additions & 3 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading