Escape backslash within string fields (#3161)

This commit is contained in:
Daniel Nelson
2017-08-23 15:17:26 -07:00
committed by GitHub
parent f253623231
commit ae24a0754b
4 changed files with 88 additions and 15 deletions

View File

@@ -77,16 +77,10 @@ func New(
// pre-allocate capacity of the fields slice
fieldlen := 0
for k, v := range fields {
for k, _ := range fields {
if strings.HasSuffix(k, `\`) {
return nil, fmt.Errorf("Metric cannot have field key ending with a backslash")
}
switch val := v.(type) {
case string:
if strings.HasSuffix(val, `\`) {
return nil, fmt.Errorf("Metric cannot have field value ending with a backslash")
}
}
// 10 bytes is completely arbitrary, but will at least prevent some
// amount of allocations. There's a small possibility this will create