mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
influxdb: escape backslashes in tag values (for alerting)
Closes #10957. Backslash escaping was already implemented on the frontend but does not work for queries executed on the backend.
This commit is contained in:
parent
710bb70746
commit
f959ba9bcf
@ -70,7 +70,7 @@ func (query *Query) renderTags() []string {
|
|||||||
} else if tag.Operator == "<" || tag.Operator == ">" {
|
} else if tag.Operator == "<" || tag.Operator == ">" {
|
||||||
textValue = tag.Value
|
textValue = tag.Value
|
||||||
} else {
|
} 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))
|
res = append(res, fmt.Sprintf(`%s"%s" %s %s`, str, tag.Key, tag.Operator, textValue))
|
||||||
|
@ -170,6 +170,12 @@ func TestInfluxdbQueryBuilder(t *testing.T) {
|
|||||||
So(strings.Join(query.renderTags(), ""), ShouldEqual, `"key" = 'value'`)
|
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() {
|
Convey("can render regular measurement", func() {
|
||||||
query := &Query{Measurement: `apa`, Policy: "policy"}
|
query := &Query{Measurement: `apa`, Policy: "policy"}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user