From 4441cad1b795a12b3e63131f258387a77a36994f Mon Sep 17 00:00:00 2001 From: s3onghyun Date: Tue, 18 Aug 2026 19:23:17 +0900 Subject: [PATCH] fix(cue): accept '-' and '.' in variable references A variable name is allowed to contain '-' and '.' (name rule "^[a-zA-Z0-9_.-]+$"), but #variableSyntaxRegex only accepted word characters. As a result a datasource referencing a validly-named variable such as $my-datasource failed CUE validation with `out of bound =~"^\$\w+$"`. Widen the reference character set to match the variable name rule. #variableSyntaxRegex is an anchored full-match validator, so this only accepts more values and is not a breaking change. Fixes perses/perses#4327 Signed-off-by: s3onghyun --- cue-test/common/datasource.cue | 8 +++++++- cue/common/variable.cue | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cue-test/common/datasource.cue b/cue-test/common/datasource.cue index 3bb2fde2..20bc8d88 100644 --- a/cue-test/common/datasource.cue +++ b/cue-test/common/datasource.cue @@ -15,4 +15,10 @@ package common myDsVarSelector: #datasourceSelector & { _kind: "MyDatasource" } -myDsVarSelector: #datasourceSelector & { datasource: "$dsVar" } \ No newline at end of file +myDsVarSelector: #datasourceSelector & { datasource: "$dsVar" } + +// Regression for perses/perses#4327: a variable name may contain '-' and '.' +// (name rule ^[a-zA-Z0-9_.-]+$), so a datasource reference to such a variable +// must validate as well. +myDsVarHyphen: #datasourceSelector & { _kind: "MyDatasource", datasource: "$ds-var" } +myDsVarDot: #datasourceSelector & { _kind: "MyDatasource", datasource: "$ds.var" } diff --git a/cue/common/variable.cue b/cue/common/variable.cue index ed51c3de..a9eea65c 100644 --- a/cue/common/variable.cue +++ b/cue/common/variable.cue @@ -13,4 +13,9 @@ package common -#variableSyntaxRegex: "^\\$\\w+$" +// A variable reference is a "$" followed by a variable name. The accepted +// character set must stay in sync with the variable name rule (#metadataName, +// "^[a-zA-Z0-9_.-]+$"), otherwise a validly-named variable such as +// "my-datasource" cannot be referenced as "$my-datasource". +// See perses/perses#4327. +#variableSyntaxRegex: "^\\$[a-zA-Z0-9_.-]+$"