mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
fix: do not break on newlines on function returns (#864)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
4aa5dac768
commit
acd829a7a0
2 changed files with 16 additions and 0 deletions
13
pkg/utils/json.go
Normal file
13
pkg/utils/json.go
Normal 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")
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue