fixed a bug with NUL in strings

This commit is contained in:
Нурлыгаянова Екатерина
2026-10-29 14:34:10 +03:00
parent 98ffd9ff45
commit 5021df4ea8
10 changed files with 177 additions and 36 deletions
+22
View File
@@ -0,0 +1,22 @@
package db
import "strings"
var (
textEncoder = strings.NewReplacer(`\`, `\\`, "\x00", `\0`)
textDecoder = strings.NewReplacer(`\\`, `\`, `\0`, "\x00")
)
func encodeText(s string) string {
if !strings.ContainsAny(s, "\\\x00") {
return s
}
return textEncoder.Replace(s)
}
func decodeText(s string) string {
if !strings.Contains(s, `\`) {
return s
}
return textDecoder.Replace(s)
}