From: Alan T. DeKok Date: Thu, 16 Nov 2023 22:24:58 +0000 (-0500) Subject: mark up when we parsed an xlat with an xlat wrapper X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5e3d07584de0bb545d70c438d0de53448b1108c;p=thirdparty%2Ffreeradius-server.git mark up when we parsed an xlat with an xlat wrapper so that the print routines can print something sane --- diff --git a/src/lib/unlang/xlat.h b/src/lib/unlang/xlat.h index 7a06b094e87..9aa8d432592 100644 --- a/src/lib/unlang/xlat.h +++ b/src/lib/unlang/xlat.h @@ -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[]; diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index f5a0dc86e79..26d146d1a5f 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -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]); diff --git a/src/tests/unit/xlat/alternation.txt.ignore b/src/tests/unit/xlat/alternation.txt similarity index 79% rename from src/tests/unit/xlat/alternation.txt.ignore rename to src/tests/unit/xlat/alternation.txt index ab04ec5c1b7..1348ca84ed6 100644 --- a/src/tests/unit/xlat/alternation.txt.ignore +++ b/src/tests/unit/xlat/alternation.txt @@ -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 diff --git a/src/tests/unit/xlat/purify.txt b/src/tests/unit/xlat/purify.txt index d0c73925afe..6e0114ecfc2 100644 --- a/src/tests/unit/xlat/purify.txt +++ b/src/tests/unit/xlat/purify.txt @@ -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!