mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/logstorage: quote logfmt strings only if they contain special chars, which could break logfmt parsing and/or reading
This commit is contained in:
parent
ebd393d8b3
commit
462b7cd597
2 changed files with 14 additions and 2 deletions
|
@ -45,7 +45,7 @@ func TestPipePackLogfmt(t *testing.T) {
|
|||
},
|
||||
}, [][]Field{
|
||||
{
|
||||
{"_msg", `_msg=x foo=abc bar="cde=ab"`},
|
||||
{"_msg", `_msg=x foo=abc bar=cde=ab`},
|
||||
{"foo", `abc`},
|
||||
{"bar", `cde=ab`},
|
||||
},
|
||||
|
|
|
@ -91,13 +91,25 @@ func getFieldValue(fields []Field, name string) string {
|
|||
|
||||
func needLogfmtQuoting(s string) bool {
|
||||
for _, c := range s {
|
||||
if !isTokenRune(c) {
|
||||
if isLogfmtSpecialChar(c) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isLogfmtSpecialChar(c rune) bool {
|
||||
if c <= 0x20 {
|
||||
return true
|
||||
}
|
||||
switch c {
|
||||
case '"', '\\':
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// RenameField renames field with the oldName to newName in Fields
|
||||
func RenameField(fields []Field, oldName, newName string) {
|
||||
if oldName == "" {
|
||||
|
|
Loading…
Reference in a new issue