]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
mark up when we parsed an xlat with an xlat wrapper
authorAlan T. DeKok <aland@freeradius.org>
Thu, 16 Nov 2023 22:24:58 +0000 (17:24 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 17 Nov 2023 14:53:43 +0000 (09:53 -0500)
so that the print routines can print something sane

src/lib/unlang/xlat.h
src/lib/unlang/xlat_tokenize.c
src/tests/unit/xlat/alternation.txt [moved from src/tests/unit/xlat/alternation.txt.ignore with 79% similarity]
src/tests/unit/xlat/purify.txt

index 7a06b094e87a3d5f7382d300a5b293045dc3ae28..9aa8d432592d40b3ab81c9a54ce556ce8ed15860 100644 (file)
@@ -116,6 +116,7 @@ typedef struct {
        bool                    can_purify;     //!< if the xlat has a pure function with pure arguments.
 
        bool                    constant;       //!< xlat is just tmpl_attr_tail_data, or XLAT_BOX
+       bool                    xlat;           //!< it's an xlat wrapper
 } xlat_flags_t;
 
 extern fr_table_num_sorted_t const xlat_action_table[];
index f5a0dc86e798802fddf9db3d033d96564fda2bfb..26d146d1a5fab78ae8579ea99e2f837fb8e8d363 100644 (file)
@@ -948,6 +948,7 @@ int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in,
                tmpl_set_xlat(node->vpt, child);
                xlat_exp_insert_tail(head, node);
 
+               child->flags.xlat = true;
                node->flags = child->flags;
                fr_assert(tmpl_xlat(node->vpt) != NULL);
 
@@ -1415,7 +1416,9 @@ ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_head_t const *head, xlat_exp_t
 
                if (tmpl_contains_xlat(node->vpt)) { /* xlat and exec */
                        if (node->vpt->quote == T_BARE_WORD) {
+                               if (node->flags.xlat) FR_SBUFF_IN_CHAR_RETURN(out, '%', '{');
                                xlat_print(out, tmpl_xlat(node->vpt), NULL);
+                               if (node->flags.xlat) FR_SBUFF_IN_CHAR_RETURN(out, '}');
                        } else {
                                FR_SBUFF_IN_CHAR_RETURN(out, fr_token_quote[node->vpt->quote]);
                                xlat_print(out, tmpl_xlat(node->vpt), fr_value_escape_by_quote[node->quote]);
similarity index 79%
rename from src/tests/unit/xlat/alternation.txt.ignore
rename to src/tests/unit/xlat/alternation.txt
index ab04ec5c1b7a379aa1474cc7a080027b1a5717ca..1348ca84ed6756a01142fbfc6e9d99b9f9eda9f8 100644 (file)
@@ -6,19 +6,19 @@ proto-dictionary radius
 #  but which print out as ( ... )
 #
 xlat literal%{%{User-Password} || 'literal'}
-match literal%{%{User-Password} || 'literal'}
+match literal%{(%{User-Password} || 'literal')}
 
 xlat %{%{User-Name} || "bar"}
-match %{%{User-Name} || "bar"}
+match %{(%{User-Name} || "bar")}
 
 xlat foo %{%{User-Name} || 'bar'} baz
-match foo %{%{User-Name} || 'bar'} baz
+match foo %{(%{User-Name} || 'bar')} baz
 
 xlat %{%{test:bar} || %{User-Name}}
-match %{%{test:bar} || %{User-Name}}
+match %{(%test(bar) || %{User-Name})}
 
 xlat %{%{test:bar} || %{%{User-Name} || 'bar'}}
-match %{%{test:bar} || %{%{User-Name} || 'bar'}}
+match %{(%test(bar) || %{(%{User-Name} || 'bar')})}
 
 xlat %{%{User-Name} || }
 match ERROR offset 19: No operand found.  Expected &ref, literal, 'quoted literal', "%{expansion}", or enum value
@@ -27,10 +27,10 @@ xlat %{%{Operator-Name} || }
 match ERROR offset 23: No operand found.  Expected &ref, literal, 'quoted literal', "%{expansion}", or enum value
 
 xlat %{%{%{User-Name} || 'foo'} || 'bar'}
-match %{%{%{User-Name} || 'foo'} || 'bar'}
+match %{(%{(%{User-Name} || 'foo')} || 'bar')}
 
 xlat %{%{%{User-Name} || 'foo'} || %{%{test:bar} || %{User-Name}}}
-match %{%{%{User-Name} || 'foo'} || %{%{test:bar} || %{User-Name}}}
+match %{(%{(%{User-Name} || 'foo')} || %{(%test(bar) || %{User-Name})})}
 
 xlat %{ || }
 match ERROR offset 4: No operand found.  Expected &ref, literal, 'quoted literal', "%{expansion}", or enum value
@@ -52,7 +52,7 @@ xlat %{%{User-Name} || 'foo'
 match ERROR offset 24: Missing closing brace
 
 xlat %{%{User-Name}:}
-match %{User-Name}:
+match %{%{User-Name}:}
 
 count
-match foo
+match 33
index d0c73925afe6cfdadeec60bec1b73b6002f89f22..6e0114ecfc25571e0cc99cfb9a8278eee2df2745 100644 (file)
@@ -196,13 +196,13 @@ match !%rcode('fail')
 #  @todo - xlat_tokenize() does not call purify
 #
 xlat_purify (string)(%{1 + 2})
-match %cast(string, (1 + 2))
+match %cast(string, %{(1 + 2)})
 
 #
 #  This is a different code path than the above.
 #
 xlat_purify (string)%{1 + 2}
-match %cast(string, (1 + 2))
+match %cast(string, %{(1 + 2)})
 
 xlat_purify "hello"
 match "hello"
@@ -221,7 +221,7 @@ match "hello 3 bob"
 #  The real run-time tests work
 #
 xlat_purify "hello %{1 + 2} bob"
-match %cast(string, "hello (1 + 2) bob")
+match %cast(string, "hello %{(1 + 2)} bob")
 
 #
 #  New syntax!