From: Alan T. DeKok Date: Sat, 7 Sep 2024 16:27:44 +0000 (-0400) Subject: eval should call xlat_tokenize_expression() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f1ed1c3e4361234fec2f0a23f991ac4f4fcb255;p=thirdparty%2Ffreeradius-server.git eval should call xlat_tokenize_expression() instead of xlat_tokenize(), as expressions can have many things in them, including math. whereas xlat_tokenize() generally just tokenizes one string --- diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index d00a02fa976..575dc91764b 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -1506,7 +1506,7 @@ static xlat_action_t xlat_func_eval(TALLOC_CTX *ctx, fr_dcursor_t *out, /* * Parse the input as a literal expansion */ - if (xlat_tokenize(rctx, + if (xlat_tokenize_expression(rctx, &rctx->ex, &FR_SBUFF_IN(arg->vb_strvalue, arg->vb_length), &(fr_sbuff_parse_rules_t){ @@ -1524,7 +1524,7 @@ static xlat_action_t xlat_func_eval(TALLOC_CTX *ctx, fr_dcursor_t *out, .runtime_el = unlang_interpret_event_list(request), }, .at_runtime = true - }, 0) < 0) { + }) < 0) { RPEDEBUG("Failed parsing expansion"); error: talloc_free(rctx); diff --git a/src/tests/keywords/attr-index-eval b/src/tests/keywords/attr-index-eval new file mode 100644 index 00000000000..ca8470313ff --- /dev/null +++ b/src/tests/keywords/attr-index-eval @@ -0,0 +1,30 @@ +uint32 index +string ref +string foo + +Filter-Id := { "a", "b" } +index := 1 + +# +# Dynamically create an attribute reference +# +ref = "Filter-Id[" + index + "]" + +# +# Evaluate the attribute as an unlang expression. +# +foo = %eval(%{ref}) + +if (foo != "b") { + test_fail +} + +ref = "1 + 2" + +foo = %eval(%{ref}) + +if (foo != 3) { + test_fail +} + +success