diff --git a/app/vmalert/notifier/alert_test.go b/app/vmalert/notifier/alert_test.go index 6612891b21..3cd032d6a8 100644 --- a/app/vmalert/notifier/alert_test.go +++ b/app/vmalert/notifier/alert_test.go @@ -52,15 +52,15 @@ func TestAlert_ExecTemplate(t *testing.T) { { name: "expression-template", alert: &Alert{ - Expr: "vm_rows>0", + Expr: `vm_rows{"label"="bar"}>0`, }, annotations: map[string]string{ - "exprEscapedQuery": "{{ $expr|queryEscape }}", - "exprEscapedPath": "{{ $expr|pathEscape }}", + "exprEscapedQuery": "{{ $expr|quotesEscape|queryEscape }}", + "exprEscapedPath": "{{ $expr|quotesEscape|pathEscape }}", }, expTpl: map[string]string{ - "exprEscapedQuery": "vm_rows%3E0", - "exprEscapedPath": "vm_rows%3E0", + "exprEscapedQuery": "vm_rows%7B%5C%22label%5C%22%3D%5C%22bar%5C%22%7D%3E0", + "exprEscapedPath": "vm_rows%7B%5C%22label%5C%22=%5C%22bar%5C%22%7D%3E0", }, }, } diff --git a/app/vmalert/notifier/template_func.go b/app/vmalert/notifier/template_func.go index 88547d1a5b..abfd8fc918 100644 --- a/app/vmalert/notifier/template_func.go +++ b/app/vmalert/notifier/template_func.go @@ -148,6 +148,9 @@ func InitTemplateFunc(externalURL *url.URL) { "queryEscape": func(q string) string { return url.QueryEscape(q) }, + "quotesEscape": func(q string) string { + return strings.Replace(q, `"`, `\"`, -1) + }, } }