From: Alan T. DeKok Date: Thu, 15 May 2025 19:38:21 +0000 (-0400) Subject: add test which currently returns an error X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f0ea0743f5c2dfc02a99f600d1b2d18f8cdf2f7;p=thirdparty%2Ffreeradius-server.git add test which currently returns an error so we have some notes for conditions in tmpl_dcursors --- diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index cf275624522..4a29349bffd 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -1410,23 +1410,28 @@ static fr_slen_t tmpl_attr_parse_filter(tmpl_attr_error_t *err, tmpl_attr_t *ar, fr_sbuff_parse_rules_t p_rules; fr_sbuff_term_t const filter_terminals = FR_SBUFF_TERMS(L("]")); + + tmp = FR_SBUFF(&our_name); + t_rules = (tmpl_rules_t) {}; + t_rules.attr = *at_rules; + /* * Unspecified child, we can create a filter starting from the children. * * @todo - When parsing the condition, we need to ensure that the condition contains a * reference to the current cursor, and we need to decide what that syntax is. */ - if ((ar->type != TMPL_ATTR_TYPE_UNSPEC) && - (!ar->ar_da || !fr_type_is_structural(ar->ar_da->type))) { - fr_strerror_printf("Invalid filter - cannot use filter on leaf attributes"); - ar->ar_num = 0; - goto error; - } + if (ar->type == TMPL_ATTR_TYPE_UNSPEC) { + t_rules.attr.namespace = fr_dict_root(at_rules->dict_def); - tmp = FR_SBUFF(&our_name); - t_rules = (tmpl_rules_t) {}; - t_rules.attr = *at_rules; - t_rules.attr.namespace = ar->ar_da; /* @todo - parent? */ + } else { + if (!ar->ar_da || !fr_type_is_structural(ar->ar_da->type)) { + fr_strerror_printf("Invalid filter - cannot use filter on leaf attributes"); + ar->ar_num = 0; + goto error; + } + t_rules.attr.namespace = ar->ar_da; + } p_rules = (fr_sbuff_parse_rules_t) { .terminals = &filter_terminals, diff --git a/src/tests/keywords/array-filter b/src/tests/keywords/array-filter new file mode 100644 index 00000000000..82c58c76725 --- /dev/null +++ b/src/tests/keywords/array-filter @@ -0,0 +1,26 @@ +# +# PRE: if +# +# Tests for dereferencing the Nth attribute +# +request += { + Class = 0x01020304, + Class = 0x05060708, + Class = 0x090a0b0c, +} + +reply.NAS-Port = 0 + +if (0) { + +foreach octets foo (request.[(Class != 0x05060708)]) { + %pairs.debug(foo) + + reply.Filter-Id += "class is " + %hex(foo) + reply.NAS-Port += 1 +} +} else { + + # this don't work. + reply.Proxy-State := request.[(. == 0x01020304)] # ERROR +}