From: Alan T. DeKok Date: Sun, 15 Sep 2024 16:37:48 +0000 (-0400) Subject: fix dcursor counting, and add test-case X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22b12196f48e4d145a44aa44ceb4ae84ee823d87;p=thirdparty%2Ffreeradius-server.git fix dcursor counting, and add test-case --- diff --git a/src/lib/server/tmpl_dcursor.c b/src/lib/server/tmpl_dcursor.c index 8a39aa9288e..10c829ad1e0 100644 --- a/src/lib/server/tmpl_dcursor.c +++ b/src/lib/server/tmpl_dcursor.c @@ -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 index 00000000000..10c2e4b8dca --- /dev/null +++ b/src/tests/keywords/foreach-key-ref @@ -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