From de9375b4d98033acdc22623194605cd9c4dbdb02 Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Mon, 9 Feb 2026 20:32:52 +0100 Subject: [PATCH 1/2] Make expandrange able to output a single value - Allow ranges with a unique value (as the range is already inclusive) - Make invalid step value a soft fail Changelog: Allow expandrange to output a single value --- libpromises/evalfunction.c | 6 ++- .../01_vars/02_functions/expand_range.cf | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 tests/acceptance/01_vars/02_functions/expand_range.cf diff --git a/libpromises/evalfunction.c b/libpromises/evalfunction.c index 1e6da00223..52f9d1b430 100644 --- a/libpromises/evalfunction.c +++ b/libpromises/evalfunction.c @@ -4558,9 +4558,11 @@ static FnCallResult FnCallExpandRange(EvalContext *ctx, ARG_UNUSED const Policy sscanf(template, "%[^[\[][%d-%d]%[^\n]", before, &from, &to, after); } - if (step_size < 1 || abs(from-to) < step_size) + if (step_size < 1) { - FatalError(ctx, "EXPANDRANGE Step size cannot be less than 1 or greater than the interval"); + assert(fp->name != NULL); + Log(LOG_LEVEL_ERR, "%s: Step size cannot be less than 1", fp->name); + return FnFailure(); } if (from == CF_NOINT || to == CF_NOINT) diff --git a/tests/acceptance/01_vars/02_functions/expand_range.cf b/tests/acceptance/01_vars/02_functions/expand_range.cf new file mode 100644 index 0000000000..8d955478c9 --- /dev/null +++ b/tests/acceptance/01_vars/02_functions/expand_range.cf @@ -0,0 +1,43 @@ +# data_regextract() test + +body common control +{ + inputs => { "../../default.cf.sub" }; + bundlesequence => { default("$(this.promise_filename)") }; +} + +bundle agent test +{ + vars: + "case1" slist => expandrange("case1[1-3]", 1); + "case1s" string => format("%S", "case1"); + "case2" slist => expandrange("case2[1-10]", 3); + "case2s" string => format("%S", "case2"); + "case3" slist => expandrange("case3[1-1]", 3); + "case3s" string => format("%S", "case3"); + "case4" slist => expandrange("case4[1-2]", 3); + "case4s" string => format("%S", "case4"); +} + +bundle agent check +{ + vars: + "actual" string => " +1 $(test.case1s) +2 $(test.case2s) +3 $(test.case3s) +4 $(test.case4s) +"; + + "expected" string => ' +1 { \"case11\", \"case12\", \"case13\" } +2 { \"case21\", \"case24\", \"case27\", \"case210\" } +3 { \"case31\" } +4 { \"case41\" } +'; + + methods: + "" usebundle => dcs_check_strcmp($(actual), $(expected), + $(this.promise_filename), + "no"); +} From f1c21c6c6af3be44cf4fbc985940ec2e9d35cdfb Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Wed, 11 Feb 2026 00:58:11 +0100 Subject: [PATCH 2/2] Fix assert --- libpromises/evalfunction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libpromises/evalfunction.c b/libpromises/evalfunction.c index 52f9d1b430..97bf208549 100644 --- a/libpromises/evalfunction.c +++ b/libpromises/evalfunction.c @@ -4539,6 +4539,8 @@ static FnCallResult FnCallMapList(EvalContext *ctx, static FnCallResult FnCallExpandRange(EvalContext *ctx, ARG_UNUSED const Policy *policy, ARG_UNUSED const FnCall *fp, const Rlist *finalargs) { + assert(fp != NULL); + Rlist *newlist = NULL; const char *template = RlistScalarValue(finalargs); char *step = RlistScalarValue(finalargs->next); @@ -4560,7 +4562,6 @@ static FnCallResult FnCallExpandRange(EvalContext *ctx, ARG_UNUSED const Policy if (step_size < 1) { - assert(fp->name != NULL); Log(LOG_LEVEL_ERR, "%s: Step size cannot be less than 1", fp->name); return FnFailure(); }