Fix tabs and carriage returns being incorrectly sanitized

This commit is contained in:
Kovid Goyal
2023-03-23 13:17:33 +05:30
parent b5c2d85837
commit e774deaef1
2 changed files with 3 additions and 14 deletions

View File

@@ -4,7 +4,6 @@ package utils
import (
"fmt"
"regexp"
"sort"
"golang.org/x/exp/constraints"
@@ -152,15 +151,3 @@ func Memset[T any](dest []T, pattern ...T) []T {
}
return dest
}
var ControlCodesPat = (&Once[*regexp.Regexp]{Run: func() *regexp.Regexp {
return regexp.MustCompile("[\x00-\x09\x0b-\x1f\x7f\u0080-\u009f]")
}}).Get
func SanitizeControlCodes(raw string, replace_with ...string) string {
r := ""
if len(replace_with) > 0 {
r = replace_with[0]
}
return ControlCodesPat().ReplaceAllLiteralString(raw, r)
}