mirror of https://github.com/sirupsen/logrus.git
Fix key of field without quoting issue
This commit is contained in:
parent
64a59449f3
commit
0fa5edc3dc
3
entry.go
3
entry.go
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -138,7 +139,7 @@ func (entry *Entry) WithFields(fields Fields) *Entry {
|
|||
fieldErr = tmp
|
||||
}
|
||||
} else {
|
||||
data[k] = v
|
||||
data[strings.TrimPrefix(strings.TrimSuffix(strconv.Quote(k), `"`), `"`)] = v
|
||||
}
|
||||
}
|
||||
return &Entry{Logger: entry.Logger, Data: data, Time: entry.Time, err: fieldErr, Context: entry.Context}
|
||||
|
|
|
@ -254,3 +254,17 @@ func TestEntryReportCallerRace(t *testing.T) {
|
|||
entry.Info("should not race")
|
||||
}()
|
||||
}
|
||||
|
||||
func TestEntryWithHardcodedField(t *testing.T) {
|
||||
out := new(bytes.Buffer)
|
||||
|
||||
l := New()
|
||||
l.SetOutput(out)
|
||||
|
||||
l.WithFields(Fields{
|
||||
"animal": "walrus",
|
||||
"stu\xff": "test\"\xff\xff\xff\xff\x30\x00\x00\x00\x00test\xee\x81\x9a",
|
||||
}).Info("A bug\nwas verified")
|
||||
assert.Contains(t, out.String(), "animal")
|
||||
assert.Contains(t, out.String(), `stu\xff`)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue