]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
handle multiple values better with list on the RHS
authorAlan T. DeKok <aland@freeradius.org>
Thu, 5 Oct 2023 19:08:27 +0000 (15:08 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 5 Oct 2023 19:20:20 +0000 (15:20 -0400)
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

src/lib/unlang/edit.c
src/tests/keywords/edit-multivalue [new file with mode: 0644]

index 00a19a4e206c4cda31dc96b530fc0e233a9d9f59..03b081874b04f63f9b7efd25bffe772a8689064d 100644 (file)
@@ -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 (file)
index 0000000..68aa3fd
--- /dev/null
@@ -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