@@ -105,9 +105,9 @@ type ConnConfig struct {
|
|||||||
// If multiple hosts were given in the Host parameter, then
|
// If multiple hosts were given in the Host parameter, then
|
||||||
// this parameter may specify a single port number to be used for all hosts,
|
// this parameter may specify a single port number to be used for all hosts,
|
||||||
// or for those that haven't port explicitly defined.
|
// or for those that haven't port explicitly defined.
|
||||||
Port uint16
|
Port uint16
|
||||||
Database string
|
Database string
|
||||||
User string // default: OS user name
|
User string // default: OS user name
|
||||||
Password string
|
Password string
|
||||||
TLSConfig *tls.Config // config for TLS connection -- nil disables TLS
|
TLSConfig *tls.Config // config for TLS connection -- nil disables TLS
|
||||||
UseFallbackTLS bool // Try FallbackTLSConfig if connecting with TLSConfig fails. Used for preferring TLS, but allowing unencrypted, or vice-versa
|
UseFallbackTLS bool // Try FallbackTLSConfig if connecting with TLSConfig fails. Used for preferring TLS, but allowing unencrypted, or vice-versa
|
||||||
@@ -307,7 +307,8 @@ type Identifier []string
|
|||||||
func (ident Identifier) Sanitize() string {
|
func (ident Identifier) Sanitize() string {
|
||||||
parts := make([]string, len(ident))
|
parts := make([]string, len(ident))
|
||||||
for i := range ident {
|
for i := range ident {
|
||||||
parts[i] = `"` + strings.Replace(ident[i], `"`, `""`, -1) + `"`
|
s := strings.Replace(ident[i], string([]byte{0}), "", -1)
|
||||||
|
parts[i] = `"` + strings.Replace(s, `"`, `""`, -1) + `"`
|
||||||
}
|
}
|
||||||
return strings.Join(parts, ".")
|
return strings.Join(parts, ".")
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-5
@@ -84,7 +84,6 @@ func TestConnect(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestConnectWithMultiHost(t *testing.T) {
|
func TestConnectWithMultiHost(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -129,7 +128,6 @@ func TestConnectWithMultiHost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestConnectWithMultiHostWritable(t *testing.T) {
|
func TestConnectWithMultiHostWritable(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -818,9 +816,9 @@ func TestParseDSN(t *testing.T) {
|
|||||||
TLSConfig: &tls.Config{
|
TLSConfig: &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
},
|
},
|
||||||
UseFallbackTLS: true,
|
UseFallbackTLS: true,
|
||||||
FallbackTLSConfig: nil,
|
FallbackTLSConfig: nil,
|
||||||
RuntimeParams: map[string]string{},
|
RuntimeParams: map[string]string{},
|
||||||
TargetSessionAttrs: pgx.ReadWriteTargetSession,
|
TargetSessionAttrs: pgx.ReadWriteTargetSession,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -2319,6 +2317,24 @@ func TestSetLogLevel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIdentifierSanitizeNullSentToServer(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
conn := mustConnect(t, *defaultConnConfig)
|
||||||
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
ident := pgx.Identifier{"foo" + string([]byte{0}) + "bar"}
|
||||||
|
|
||||||
|
var n int64
|
||||||
|
err := conn.QueryRow(`select 1 as ` + ident.Sanitize()).Scan(&n)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if n != 1 {
|
||||||
|
t.Fatal("unexpected n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIdentifierSanitize(t *testing.T) {
|
func TestIdentifierSanitize(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -2346,6 +2362,10 @@ func TestIdentifierSanitize(t *testing.T) {
|
|||||||
ident: pgx.Identifier{`you should " not do this`, `please don't`},
|
ident: pgx.Identifier{`you should " not do this`, `please don't`},
|
||||||
expected: `"you should "" not do this"."please don't"`,
|
expected: `"you should "" not do this"."please don't"`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ident: pgx.Identifier{`you should ` + string([]byte{0}) + `not do this`},
|
||||||
|
expected: `"you should not do this"`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user