Mysql: dsn.go parses the DSN err: "invalid DSN: did you forget to escape a param value"

Created on 26 Jul 2019  路  1Comment  路  Source: go-sql-driver/mysql

Issue description

Function ParseDSN in dsn.go parses dsn mistakenly while dsn contains a parameter "loc=Asia/Shanghai".

Analyze

As author may consider last '/' may not appeared after dbname, this func parse DSN via finding the last '/' of DSN. But parameter "loc" specifies time zone like UTC, America/Creston, Asia/Shanghai,Asia/Almaty,Eurpoe/Istanbul. It may contains "/" and this '/' maybe the last '/' causes this err.

Error log

ParseDSN:dsn: username:password@protocol(address)/dbname?param=value&loc=Asia/Shanghai
ParseDSN:dsn: 97
ParseDSN:dsn: address)/dbname?param=value&loc=Asia
--- FAIL: TestDSNParser (0.00s)
dsn_test.go:81: invalid DSN: did you forget to escape a param value?
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x63f604]

Configuration

commit SHA:
877a9775f06853f611fb2d4e817d92479242d1cd

Go version: go version go1.12.7 windows/amd64

Server version: MySQL 5.6

Server OS: NeoKylin Linux Server 7.0 (loongson) and Windows 10

wontfix

Most helpful comment

From the README:

Please keep in mind, that param values must be url.QueryEscape'ed. Alternatively you can manually replace the / with %2F. For example US/Pacific would be loc=US%2FPacific.

>All comments

From the README:

Please keep in mind, that param values must be url.QueryEscape'ed. Alternatively you can manually replace the / with %2F. For example US/Pacific would be loc=US%2FPacific.

Was this page helpful?
0 / 5 - 0 ratings