]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
eval should call xlat_tokenize_expression()
authorAlan T. DeKok <aland@freeradius.org>
Sat, 7 Sep 2024 16:27:44 +0000 (12:27 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 9 Sep 2024 16:33:50 +0000 (12:33 -0400)
instead of xlat_tokenize(), as expressions can have many things
in them, including math.  whereas xlat_tokenize() generally just
tokenizes one string

src/lib/unlang/xlat_builtin.c
src/tests/keywords/attr-index-eval [new file with mode: 0644]

index d00a02fa97610de6a0fc80cbe968fa97a17baf3b..575dc91764b5c406c236322a61cc27f4ed503292 100644 (file)
@@ -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 (file)
index 0000000..ca84703
--- /dev/null
@@ -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