fix: do not break on newlines on function returns (#864)

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto 2023-08-04 21:46:36 +02:00 committed by GitHub
parent 4aa5dac768
commit acd829a7a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

13
pkg/utils/json.go Normal file
View file

@ -0,0 +1,13 @@
package utils
import "regexp"
var matchNewlines = regexp.MustCompile(`[\r\n]`)
const doubleQuote = `"[^"\\]*(?:\\[\s\S][^"\\]*)*"`
func EscapeNewLines(s string) string {
return regexp.MustCompile(doubleQuote).ReplaceAllStringFunc(s, func(s string) string {
return matchNewlines.ReplaceAllString(s, "\\n")
})
}