File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ Jian Zhen <zhenjl at gmail.com>
2727Joshua Prunier <joshua.prunier at gmail.com>
2828Julien Schmidt <go-sql-driver at julienschmidt.com>
2929Kamil Dziedzic <kamil at klecza.pl>
30+ Kevin Malachowski <kevin at chowski.com>
3031Leonardo YongUk Kim <dalinaum at gmail.com>
3132Lucas Liu <extrafliu at gmail.com>
3233Luke Scott <luke at webconnex.com>
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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+
119137func TestDSNUnsafeCollation (t * testing.T ) {
120138 _ , err := parseDSN ("/dbname?collation=gbk_chinese_ci&interpolateParams=true" )
121139 if err != errInvalidDSNUnsafeCollation {
You can’t perform that action at this time.
0 commit comments