mirror of
https://github.com/grafana/grafana.git
synced 2025-02-09 23:16:16 -06:00
CloudWatch: Fix apostrophes in dimension values not being escaped (#87182)
This commit is contained in:
parent
a979417700
commit
6851ad9f8c
@ -99,7 +99,7 @@ func buildSearchExpression(query *models.CloudWatchQuery, stat string) string {
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
values := escapeDoubleQuotes(knownDimensions[key])
|
||||
values := escapeQuotes(knownDimensions[key])
|
||||
valueExpression := join(values, " OR ", `"`, `"`)
|
||||
if len(knownDimensions[key]) > 1 {
|
||||
valueExpression = fmt.Sprintf(`(%s)`, valueExpression)
|
||||
@ -150,10 +150,11 @@ func buildSearchExpressionLabel(query *models.CloudWatchQuery) string {
|
||||
return label
|
||||
}
|
||||
|
||||
func escapeDoubleQuotes(arr []string) []string {
|
||||
func escapeQuotes(arr []string) []string {
|
||||
result := []string{}
|
||||
for _, value := range arr {
|
||||
value = strings.ReplaceAll(value, `"`, `\"`)
|
||||
value = strings.ReplaceAll(value, `'`, `\'`)
|
||||
result = append(result, value)
|
||||
}
|
||||
|
||||
|
@ -472,7 +472,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
"lb4": {`lb4""`},
|
||||
"lb4": {`lb4's""'`},
|
||||
},
|
||||
Period: 300,
|
||||
Expression: "",
|
||||
@ -480,7 +480,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
}
|
||||
res := buildSearchExpression(query, "Average")
|
||||
|
||||
assert.Contains(t, res, `lb4\"\"`, "Expected escape double quotes")
|
||||
assert.Contains(t, res, `lb4\'s\"\"\'`, "Expected escaped quotes")
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user