]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix dcursor counting, and add test-case
authorAlan T. DeKok <aland@freeradius.org>
Sun, 15 Sep 2024 16:37:48 +0000 (12:37 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 16 Sep 2024 14:27:50 +0000 (10:27 -0400)
src/lib/server/tmpl_dcursor.c
src/tests/keywords/foreach-key-ref [new file with mode: 0644]

index 8a39aa9288eb66558f8a1a855cadf5deb2e49f22..10c829ad1e0f3b97c878f7c0b817bbb44533b35c 100644 (file)
@@ -59,7 +59,6 @@ static void *_tmpl_cursor_child_next(fr_dlist_head_t *list, void *curr, void *uc
 
        while ((vp = fr_dlist_next(list, vp))) {
                if (fr_dict_attr_cmp(ns->ar->ar_da, vp->da) == 0) break;
-               ns->num++;
        }
 
        return vp;
@@ -218,8 +217,14 @@ fr_pair_t *_tmpl_cursor_eval(fr_pair_t *curr, tmpl_dcursor_ctx_t *cc)
                /*
                 *      @todo - arguably we shouldn't try building things here.
                 */
-               if (!vp) pop = true;    /* pop only when we're done */
+               if (!vp) {
+                       pop = true;     /* pop only when we're done */
+
+               } else if (num != NUM_COUNT) {
+                       ns->num++;
+               }
                fr_dcursor_next(&ns->cursor);
+
                break;
 
        /*
diff --git a/src/tests/keywords/foreach-key-ref b/src/tests/keywords/foreach-key-ref
new file mode 100644 (file)
index 0000000..10c2e4b
--- /dev/null
@@ -0,0 +1,25 @@
+#
+#  PRE: attr-ref-assign
+#
+string total
+
+Tmp-String-0 := { "a", "b", "c", "d" }
+
+Tmp-String-1 := { "a", "b", "c", "d" }
+
+#
+#  Ensure that attributes can be referenced, and
+#  that the count is correct.
+#
+foreach string key, string name (Tmp-String-0[*]) {
+       total += key
+       total += " = '"
+       total += %eval(%{key})
+       total += "', "
+}
+
+if (total != "request.Tmp-String-0[0] = 'a', request.Tmp-String-0[1] = 'b', request.Tmp-String-0[2] = 'c', request.Tmp-String-0[3] = 'd', ") {
+       test_fail
+}
+
+success