diff --git a/internal/docker/logfmt.go b/internal/docker/logfmt.go index ade2b20f..87502351 100644 --- a/internal/docker/logfmt.go +++ b/internal/docker/logfmt.go @@ -15,7 +15,6 @@ func ParseLogFmt(log string) (*orderedmap.OrderedMap[string, string], error) { for i := 0; i < len(log); i++ { char := log[i] - if isKey { if char == '=' { if i == start { @@ -48,9 +47,6 @@ func ParseLogFmt(log string) (*orderedmap.OrderedMap[string, string], error) { inQuotes = true start = i + 1 } else if char == ' ' { - if i == start { - return nil, errors.New("invalid format: value is empty") - } value = log[start:i] result.Set(key, value) isKey = true @@ -75,9 +71,6 @@ func ParseLogFmt(log string) (*orderedmap.OrderedMap[string, string], error) { if inQuotes { return nil, errors.New("invalid format: unclosed quotes") } - if start >= len(log) { - return nil, errors.New("invalid format: value is empty") - } value = log[start:] result.Set(key, value) } diff --git a/internal/docker/logfmt_test.go b/internal/docker/logfmt_test.go index 717ad20e..65a18de6 100644 --- a/internal/docker/logfmt_test.go +++ b/internal/docker/logfmt_test.go @@ -9,7 +9,6 @@ import ( ) func TestParseLog(t *testing.T) { - tests := []struct { name string log string @@ -35,10 +34,27 @@ func TestParseLog(t *testing.T) { wantErr: true, }, { - name: "Invalid log with key without value", - log: "key1=value1 key2=", - want: nil, - wantErr: true, + name: "Valid log with key and trailing no value", + log: "key1=value1 key2=", + want: orderedmap.New[string, string]( + orderedmap.WithInitialData( + orderedmap.Pair[string, string]{Key: "key1", Value: "value1"}, + orderedmap.Pair[string, string]{Key: "key2", Value: ""}, + ), + ), + wantErr: false, + }, + { + name: "Valid log with key and no values", + log: "key1=value1 key2= key3=bar", + want: orderedmap.New[string, string]( + orderedmap.WithInitialData( + orderedmap.Pair[string, string]{Key: "key1", Value: "value1"}, + orderedmap.Pair[string, string]{Key: "key2", Value: ""}, + orderedmap.Pair[string, string]{Key: "key3", Value: "bar"}, + ), + ), + wantErr: false, }, { name: "Valid log",