Skip to content

Commit c9c5955

Browse files
committed
Merge pull request mysqljs#397 from Carrotman42/master
QueryUnescape the tlsConfig name during DSN parsing.
2 parents bb006fd + 5e93316 commit c9c5955

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Jian Zhen <zhenjl at gmail.com>
2727
Joshua Prunier <joshua.prunier at gmail.com>
2828
Julien Schmidt <go-sql-driver at julienschmidt.com>
2929
Kamil Dziedzic <kamil at klecza.pl>
30+
Kevin Malachowski <kevin at chowski.com>
3031
Leonardo YongUk Kim <dalinaum at gmail.com>
3132
Lucas Liu <extrafliu at gmail.com>
3233
Luke Scott <luke at webconnex.com>

utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ func parseDSNParams(cfg *config, params string) (err error) {
267267
if boolValue {
268268
cfg.tls = &tls.Config{}
269269
}
270+
} else if value, err := url.QueryUnescape(value); err != nil {
271+
return fmt.Errorf("Invalid value for tls config name: %v", err)
270272
} else {
271273
if strings.ToLower(value) == "skip-verify" {
272274
cfg.tls = &tls.Config{InsecureSkipVerify: true}

utils_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"crypto/tls"
1414
"encoding/binary"
1515
"fmt"
16+
"net/url"
1617
"testing"
1718
"time"
1819
)
@@ -116,6 +117,23 @@ func TestDSNWithCustomTLS(t *testing.T) {
116117
DeregisterTLSConfig("utils_test")
117118
}
118119

120+
func TestDSNWithCustomTLS_queryEscape(t *testing.T) {
121+
const configKey = "&%!:"
122+
dsn := "user:password@tcp(localhost:5555)/dbname?tls=" + url.QueryEscape(configKey)
123+
name := "foohost"
124+
tlsCfg := tls.Config{ServerName: name}
125+
126+
RegisterTLSConfig(configKey, &tlsCfg)
127+
128+
cfg, err := parseDSN(dsn)
129+
130+
if err != nil {
131+
t.Error(err.Error())
132+
} else if cfg.tls.ServerName != name {
133+
t.Errorf("Did not get the correct TLS ServerName (%s) parsing DSN (%s).", name, dsn)
134+
}
135+
}
136+
119137
func TestDSNUnsafeCollation(t *testing.T) {
120138
_, err := parseDSN("/dbname?collation=gbk_chinese_ci&interpolateParams=true")
121139
if err != errInvalidDSNUnsafeCollation {

0 commit comments

Comments
 (0)