mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-18 14:40:26 +01:00
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
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:
parent
f825a9de80
commit
0a61222627
@ -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 New Issue
Block a user