mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Remove 0 bytes when sanitizing identifiers
Port of 95ea78048a9569250c078d1965a235a214239960 from v3.
This commit is contained in:
parent
a7e821c99c
commit
ab1edc79e0
3
conn.go
3
conn.go
@ -78,7 +78,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, ".")
|
||||||
}
|
}
|
||||||
|
@ -647,6 +647,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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user