Merge pull request #10959 from grafana/10957_influx_escaping

influxdb: escape backslashes in tag values (for alerting)
This commit is contained in:
Carl Bergquist 2018-02-19 15:28:55 +01:00 committed by GitHub
commit af7ede6ec5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -70,7 +70,7 @@ func (query *Query) renderTags() []string {
} else if tag.Operator == "<" || tag.Operator == ">" {
textValue = tag.Value
} else {
textValue = fmt.Sprintf("'%s'", tag.Value)
textValue = fmt.Sprintf("'%s'", strings.Replace(tag.Value, `\`, `\\`, -1))
}
res = append(res, fmt.Sprintf(`%s"%s" %s %s`, str, tag.Key, tag.Operator, textValue))

View File

@ -170,6 +170,12 @@ func TestInfluxdbQueryBuilder(t *testing.T) {
So(strings.Join(query.renderTags(), ""), ShouldEqual, `"key" = 'value'`)
})
Convey("can escape backslashes when rendering string tags", func() {
query := &Query{Tags: []*Tag{{Operator: "=", Value: `C:\test\`, Key: "key"}}}
So(strings.Join(query.renderTags(), ""), ShouldEqual, `"key" = 'C:\\test\\'`)
})
Convey("can render regular measurement", func() {
query := &Query{Measurement: `apa`, Policy: "policy"}