]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
don't pull casts into in-place expressions
authorAlan T. DeKok <aland@freeradius.org>
Sun, 8 Oct 2023 12:00:32 +0000 (08:00 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 8 Oct 2023 12:00:32 +0000 (08:00 -0400)
because that would change how the text inside of the expression
is parsed, and we don't want that

src/lib/unlang/xlat_tokenize.c
src/tests/unit/xlat/purify.txt

index 2376e2f2aea2d810526b0a35f95c09595b7516ef..30e22fc36d5a53accd9367b91653370ca75b86b7 100644 (file)
@@ -989,13 +989,17 @@ int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in,
                char *fmt;
                xlat_exp_t *node;
                xlat_exp_head_t *child;
+               tmpl_rules_t my_rules = *t_rules;
 
                fr_sbuff_set(in, &s_m);         /* backtrack to the start of the expression */
 
                MEM(node = xlat_exp_alloc(head, XLAT_TMPL, NULL, 0));
                MEM(node->vpt = tmpl_alloc(node, TMPL_TYPE_XLAT, T_BARE_WORD, "", 1));
 
-               ret = xlat_tokenize_expression(node->vpt, &child, in, &attr_p_rules, t_rules);
+               my_rules.enumv = NULL;
+               my_rules.cast = FR_TYPE_NULL;
+
+               ret = xlat_tokenize_expression(node->vpt, &child, in, &attr_p_rules, &my_rules);
                if (ret <= 0) {
                        talloc_free(node);
                        return ret;
index 1a258eb035e8e1a7d4c737371d89dda2463e7b79..e98ec192a1c15c825691efd39c26489298e8d4c0 100644 (file)
@@ -193,14 +193,16 @@ match !%{rcode:'fail'}
 #
 #  Casts and such
 #
-xlat_purify (string)(%{expr:1})
-match "1"
+#  @todo - xlat_tokenize() does not call purify
+#
+xlat_purify (string)(%{1 + 2})
+match %(cast:string (1 + 2))
 
 #
 #  This is a different code path than the above.
 #
-xlat_purify (string)%{expr:1}
-match "1"
+xlat_purify (string)%{1 + 2}
+match %(cast:string (1 + 2))
 
 xlat_purify "hello"
 match "hello"
@@ -208,11 +210,11 @@ match "hello"
 #
 #  String concatenation
 #
-xlat_purify "hello " + (string)%{expr:1}
-match "hello 1"
+xlat_purify "hello " + (string)%{1 + 2}
+match "hello 3"
 
-xlat_purify "hello " + (string)%{expr:1} + " bob"
-match "hello 1 bob"
+xlat_purify "hello " + (string)%{1 + 2} + " bob"
+match "hello 3 bob"
 
 #
 #  This should be the same as above, but it isn't!