mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-24 06:28:42 +01:00
fix: supports empty values for logfmt (#3300)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user