forked from jamf/go-mysqldump
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sanitize.go
27 lines (24 loc) · 651 Bytes
/
sanitize.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package mysqldump
import "strings"
var lazyMySQLReplacer *strings.Replacer
// sanitize MySQL based on
// https://dev.mysql.com/doc/refman/8.0/en/string-literals.html table 9.1
// needs to be placed in either a single or a double quoted string
func sanitize(input string) string {
if lazyMySQLReplacer == nil {
lazyMySQLReplacer = strings.NewReplacer(
"\x00", "\\0",
"'", "\\'",
"\"", "\\\"",
"\b", "\\b",
"\n", "\\n",
"\r", "\\r",
// "\t", "\\t", Tab literals are acceptable in reads
"\x1A", "\\Z", // ASCII 26 == x1A
"\\", "\\\\",
// "%", "\\%",
// "_", "\\_",
)
}
return lazyMySQLReplacer.Replace(input)
}