File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,8 @@ func parseDSNParams(cfg *config, params string) (err error) {
267
267
if boolValue {
268
268
cfg .tls = & tls.Config {}
269
269
}
270
+ } else if value , err := url .QueryUnescape (value ); err != nil {
271
+ return fmt .Errorf ("Invalid value for tls config name: %v" , err )
270
272
} else {
271
273
if strings .ToLower (value ) == "skip-verify" {
272
274
cfg .tls = & tls.Config {InsecureSkipVerify : true }
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import (
13
13
"crypto/tls"
14
14
"encoding/binary"
15
15
"fmt"
16
+ "net/url"
16
17
"testing"
17
18
"time"
18
19
)
@@ -116,6 +117,23 @@ func TestDSNWithCustomTLS(t *testing.T) {
116
117
DeregisterTLSConfig ("utils_test" )
117
118
}
118
119
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
+
119
137
func TestDSNUnsafeCollation (t * testing.T ) {
120
138
_ , err := parseDSN ("/dbname?collation=gbk_chinese_ci&interpolateParams=true" )
121
139
if err != errInvalidDSNUnsafeCollation {
You can’t perform that action at this time.
0 commit comments