Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions libpromises/evalfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -4558,9 +4560,10 @@ 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");
Log(LOG_LEVEL_ERR, "%s: Step size cannot be less than 1", fp->name);
return FnFailure();
}

if (from == CF_NOINT || to == CF_NOINT)
Expand Down
43 changes: 43 additions & 0 deletions tests/acceptance/01_vars/02_functions/expand_range.cf
Original file line number Diff line number Diff line change
@@ -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");
}
Loading