From: Alan T. DeKok Date: Sun, 8 Oct 2023 12:00:32 +0000 (-0400) Subject: don't pull casts into in-place expressions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78eea2b31ab86716bbbd1c852b075a876b5458ad;p=thirdparty%2Ffreeradius-server.git don't pull casts into in-place expressions because that would change how the text inside of the expression is parsed, and we don't want that --- diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 2376e2f2ae..30e22fc36d 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -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; diff --git a/src/tests/unit/xlat/purify.txt b/src/tests/unit/xlat/purify.txt index 1a258eb035..e98ec192a1 100644 --- a/src/tests/unit/xlat/purify.txt +++ b/src/tests/unit/xlat/purify.txt @@ -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!