From 80d502eb296db0ea98f3146c90d4e911a614a579 Mon Sep 17 00:00:00 2001 From: Vladimir Urushev Date: Sat, 16 Nov 2024 17:24:40 +0100 Subject: [PATCH] fix: fixes log parser (#3398) --- internal/docker/logfmt.go | 2 +- internal/docker/logfmt_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/docker/logfmt.go b/internal/docker/logfmt.go index 87502351d28f..f8652dcc46a8 100644 --- a/internal/docker/logfmt.go +++ b/internal/docker/logfmt.go @@ -17,7 +17,7 @@ func ParseLogFmt(log string) (*orderedmap.OrderedMap[string, string], error) { char := log[i] if isKey { if char == '=' { - if i == start { + if start >= i { return nil, errors.New("invalid format: key is empty") } key = log[start:i] diff --git a/internal/docker/logfmt_test.go b/internal/docker/logfmt_test.go index 65a18de68b30..b12c2961858d 100644 --- a/internal/docker/logfmt_test.go +++ b/internal/docker/logfmt_test.go @@ -67,6 +67,12 @@ func TestParseLog(t *testing.T) { ), wantErr: false, }, + { + name: "Broken format with unexpected quotes", + log: `key1=value"1"= key2="value2"`, + want: nil, + wantErr: true, + }, { name: "Invalid log with unclosed quotes", log: "key1=\"value1 key2=value2",