fix(outputs.mqtt): Preserve leading slash in topic (#14582)
This commit is contained in:
parent
9aee2681bb
commit
7cafdaf2ce
|
|
@ -908,6 +908,11 @@ func TestGenerateTopicName(t *testing.T) {
|
|||
pattern: "double//slashes//are//ignored",
|
||||
want: "double/slashes/are/ignored",
|
||||
},
|
||||
{
|
||||
name: "preserve leading forward slash",
|
||||
pattern: "/this/is/a/topic",
|
||||
want: "/this/is/a/topic",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -54,5 +54,8 @@ func (t *TopicNameGenerator) Generate(hostname string, m telegraf.Metric) (strin
|
|||
if topic == "" {
|
||||
return m.Name(), nil
|
||||
}
|
||||
if strings.HasPrefix(b.String(), "/") {
|
||||
topic = "/" + topic
|
||||
}
|
||||
return topic, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue