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"'); + }); +});