From 672330bd70d93ea242c73b0725115acbfb582b7e Mon Sep 17 00:00:00 2001 From: Flying Musk Date: Sun, 24 May 2026 15:45:59 -0700 Subject: [PATCH] test(ui): cover PromQL label name quoting Signed-off-by: Flying Musk --- web/ui/mantine-ui/src/promql/utils.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/web/ui/mantine-ui/src/promql/utils.test.ts b/web/ui/mantine-ui/src/promql/utils.test.ts index 5166a6ffbf..190b20c0d7 100644 --- a/web/ui/mantine-ui/src/promql/utils.test.ts +++ b/web/ui/mantine-ui/src/promql/utils.test.ts @@ -3,6 +3,7 @@ import { getNonParenNodeType, containsPlaceholders, nodeValueType, + maybeQuoteLabelName, } from "./utils"; import { nodeType, valueType, binaryOperatorType } from "./ast"; @@ -159,3 +160,16 @@ describe("nodeValueType", () => { ).toBe(valueType.vector); }); }); + +describe("maybeQuoteLabelName", () => { + it("does not quote valid PromQL label names", () => { + expect(maybeQuoteLabelName("job")).toBe("job"); + expect(maybeQuoteLabelName("status_code")).toBe("status_code"); + }); + + it("quotes and escapes label names with extended characters", () => { + expect(maybeQuoteLabelName("service.version")).toBe('"service.version"'); + expect(maybeQuoteLabelName("team/name")).toBe('"team/name"'); + expect(maybeQuoteLabelName('team"name')).toBe('"team\\"name"'); + }); +});