mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-22 16:36:27 +01:00
f8aa445945
The %q formatter may result in incorrectly formatted JSON string if the original string
contains special chars such as \x1b . They must be encoded as \u001b , otherwise the resulting JSON string
cannot be parsed by JSON parsers.
This is a follow-up for c0caa69939
See https://github.com/VictoriaMetrics/victorialogs-datasource/issues/24
11 lines
204 B
Go
11 lines
204 B
Go
package stringsutil
|
|
|
|
import (
|
|
"github.com/valyala/quicktemplate"
|
|
)
|
|
|
|
// JSONString returns JSON-quoted s.
|
|
func JSONString(s string) string {
|
|
return string(quicktemplate.AppendJSONString(nil, s, true))
|
|
}
|