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{
|
}, [][]Field{
|
||||||
{
|
{
|
||||||
{"_msg", `_msg=x foo=abc bar="cde=ab"`},
|
{"_msg", `_msg=x foo=abc bar=cde=ab`},
|
||||||
{"foo", `abc`},
|
{"foo", `abc`},
|
||||||
{"bar", `cde=ab`},
|
{"bar", `cde=ab`},
|
||||||
},
|
},
|
||||||
|
|
|
@ -91,13 +91,25 @@ func getFieldValue(fields []Field, name string) string {
|
||||||
|
|
||||||
func needLogfmtQuoting(s string) bool {
|
func needLogfmtQuoting(s string) bool {
|
||||||
for _, c := range s {
|
for _, c := range s {
|
||||||
if !isTokenRune(c) {
|
if isLogfmtSpecialChar(c) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
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
|
// RenameField renames field with the oldName to newName in Fields
|
||||||
func RenameField(fields []Field, oldName, newName string) {
|
func RenameField(fields []Field, oldName, newName string) {
|
||||||
if oldName == "" {
|
if oldName == "" {
|
||||||
|
|
Loading…
Reference in a new issue