From 39b09f2c4af27a3ed19ab8def20ea094df8f65e5 Mon Sep 17 00:00:00 2001 From: jinhua luo Date: Tue, 25 Jun 2019 01:05:28 +0800 Subject: [PATCH 1/2] cast bytea to make []byte suitable for both string and binary string types --- internal/sanitize/sanitize.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/sanitize/sanitize.go b/internal/sanitize/sanitize.go index 53543b89..8939d797 100644 --- a/internal/sanitize/sanitize.go +++ b/internal/sanitize/sanitize.go @@ -87,7 +87,7 @@ func QuoteString(str string) string { } func QuoteBytes(buf []byte) string { - return `'\x` + hex.EncodeToString(buf) + "'" + return `'\x` + hex.EncodeToString(buf) + "'::bytea" } type sqlLexer struct { From e07faf207d03a337183040882337aa0d7dd2e743 Mon Sep 17 00:00:00 2001 From: jinhua luo Date: Tue, 25 Jun 2019 02:12:56 +0800 Subject: [PATCH 2/2] adjust the test for the patch --- internal/sanitize/sanitize_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/sanitize/sanitize_test.go b/internal/sanitize/sanitize_test.go index 9597840e..f4337253 100644 --- a/internal/sanitize/sanitize_test.go +++ b/internal/sanitize/sanitize_test.go @@ -108,7 +108,7 @@ func TestQuerySanitize(t *testing.T) { { query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}}, args: []interface{}{[]byte{0, 1, 2, 3, 255}}, - expected: `select '\x00010203ff'`, + expected: `select '\x00010203ff'::bytea`, }, { query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}},