From: Alan T. DeKok Date: Thu, 5 Oct 2023 19:08:27 +0000 (-0400) Subject: handle multiple values better with list on the RHS X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=409c9c2d41afabbf5115e99ef053c5122e836fe8;p=thirdparty%2Ffreeradius-server.git handle multiple values better with list on the RHS If we have :=, then create multiple values. if we have other operators, then only create the first one, and then apply the operations to it don't create multiple copies of local variables --- diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index 00a19a4e20..03b081874b 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -673,6 +673,21 @@ static int apply_edits_to_leaf(request_t *request, unlang_frame_state_edit_t *st if (single) goto done; + /* + * Now that the attribute has been created, go apply the rest of the values to the attribute. + */ + if (!((map->op == T_OP_EQ) || (map->op == T_OP_SET))) { + box = fr_dcursor_next(&cursor); + if (!box) goto done; + + goto apply_op; + } + + if (current->lhs.vp->da->flags.local) { + RWDEBUG("Ignoring extra values for local variable"); + goto done; + } + /* * Loop over the remaining items, adding the VPs we've just created. */ @@ -702,6 +717,7 @@ static int apply_edits_to_leaf(request_t *request, unlang_frame_state_edit_t *st if (!current->lhs.vp) return -1; #endif +apply_op: /* * All other operators are "modify in place", of the existing current->lhs.vp */ diff --git a/src/tests/keywords/edit-multivalue b/src/tests/keywords/edit-multivalue new file mode 100644 index 0000000000..68aa3fde7f --- /dev/null +++ b/src/tests/keywords/edit-multivalue @@ -0,0 +1,43 @@ +string foo +string bar +string baz + +&baz = "a,b,c,d,e" + +# +# Append, don't create multiple versions +# +&bar += %explode(%{baz}, ',') + +if !(&bar == "abcde") { + test_fail +} + +# +# This is a warning. We only create one copy of "foo". +# +# We cannot have multiple copies of local variables. There's no real +# reason why, but for now it's safer to be limited. +# +&foo := %explode(%{baz}, ',') +if !(&foo[#] == 1) { + test_fail +} + +# +# Append +# +&Reply-Message = "foo" + +&Reply-Message += { "a", "b", "c" } + +if !(&Reply-Message == "fooabc") { + test_fail +} + +&Filter-Id := { "a", "b", "c" } +if !(&Filter-Id[#] == 3) { + test_fail +} + +success