lib/logstorage: quote logfmt strings only if they contain special chars, which could break logfmt parsing and/or reading
Some checks are pending
build / Build (push) Waiting to run
CodeQL Go / Analyze (push) Waiting to run
main / lint (push) Waiting to run
main / test (test-full) (push) Blocked by required conditions
main / test (test-full-386) (push) Blocked by required conditions
main / test (test-pure) (push) Blocked by required conditions

(cherry picked from commit 462b7cd597)
This commit is contained in:
Aliaksandr Valialkin 2024-10-07 14:31:16 +02:00 committed by hagen1778
parent f825a9de80
commit 0a61222627
No known key found for this signature in database
GPG Key ID: 3BF75F3741CA9640
2 changed files with 14 additions and 2 deletions

View File

@ -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`},
},

View File

@ -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 == "" {