Replace invalid characters with UTF8 replacement char.

This commit is contained in:
Martin Dosch 2023-08-10 13:42:31 +02:00
parent 5d8790b222
commit 2f76178a22
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D
2 changed files with 3 additions and 2 deletions

View File

@ -3,6 +3,7 @@
## Unreleased
### Changed
- Properly close connection to server if ^C is pressed in interactive mode.
- Replace invalid characters by UTF8 replacement char.
## [v0.6.1] 2023-07-25
### Changed

View File

@ -19,9 +19,9 @@ import (
func validUTF8(s string) string {
// Remove invalid code points.
s = strings.ToValidUTF8(s, "")
s = strings.ToValidUTF8(s, "<EFBFBD>")
reg := regexp.MustCompile(`[\x{0000}-\x{0008}\x{000B}\x{000C}\x{000E}-\x{001F}]`)
s = reg.ReplaceAllString(s, "")
s = reg.ReplaceAllString(s, "<EFBFBD>")
return s
}