Skip to content

Commit 710984e

Browse files
chore(ui): Test escape matcher values in filters (#4862)
Signed-off-by: kkh <kkhdevs@gmail.com> Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com> Co-authored-by: Solomon Jacobs <solomonjacobs@protonmail.com>
1 parent 42d7907 commit 710984e

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

ui/app/tests/Filter.elm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ parseMatcher =
1616
, test "should parse empty matcher value" <|
1717
\() ->
1818
Expect.equal (Just (Matcher "alertname" Eq "")) (Utils.Filter.parseMatcher "alertname=\"\"")
19+
, test "should unescape quoted matcher value" <|
20+
\() ->
21+
Expect.equal
22+
(Just (Matcher "alertname" Eq "foo\"bar"))
23+
(Utils.Filter.parseMatcher "alertname=\"foo\\\"bar\"")
24+
, test "should unescape backslash matcher value" <|
25+
\() ->
26+
Expect.equal
27+
(Just (Matcher "alertname" Eq "foo\\bar"))
28+
(Utils.Filter.parseMatcher "alertname=\"foo\\\\bar\"")
1929
, fuzz (tuple ( string, string )) "should parse random matcher string" <|
2030
\( key, value ) ->
2131
if List.map isNotEmptyTrimmedAlphabetWord [ key, value ] /= [ True, True ] then
@@ -83,4 +93,10 @@ stringifyFilter =
8393
, { key = "baz", op = RegexMatch, value = "quux.*" }
8494
]
8595
)
96+
, test "escapes matcher values" <|
97+
\() ->
98+
Expect.equal "{foo=\"bar\\\"baz\\\\qux\"}"
99+
(Utils.Filter.stringifyFilter
100+
[ { key = "foo", op = Eq, value = "bar\"baz\\qux" } ]
101+
)
86102
]

0 commit comments

Comments
 (0)