Remove 0 bytes when sanitizing identifiers

Port of 95ea78048a from v3.
pull/586/head
Jack Christensen 2019-08-03 09:51:03 -05:00
parent a7e821c99c
commit ab1edc79e0
2 changed files with 6 additions and 1 deletions

View File

@ -78,7 +78,8 @@ type Identifier []string
func (ident Identifier) Sanitize() string {
parts := make([]string, len(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, ".")
}

View File

@ -647,6 +647,10 @@ func TestIdentifierSanitize(t *testing.T) {
ident: pgx.Identifier{`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 {