From: Alan T. DeKok Date: Fri, 27 May 2022 19:01:46 +0000 (-0400) Subject: print "true" and "false" in more situations X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39cbd061992d1073c7883db02c49f1110cefeebb;p=thirdparty%2Ffreeradius-server.git print "true" and "false" in more situations --- diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index ee19cfc128e..f3d0302d4df 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -1114,6 +1114,19 @@ static ssize_t tokenize_field(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_ return -fr_sbuff_used(&our_in); } + /* + * It would be nice if tmpl_afrom_substr() did this :( + */ + if (quote != T_BARE_WORD) { + if (!fr_sbuff_is_char(&our_in, fr_token_quote[quote])) { + fr_strerror_const("Unterminated string"); + fr_sbuff_advance(&our_in, slen * -1); + goto error; + } + + fr_sbuff_advance(&our_in, 1); + } + node->vpt = vpt; node->quote = quote; node->fmt = vpt->name; @@ -1121,8 +1134,23 @@ static ssize_t tokenize_field(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_ node->flags.pure = tmpl_is_data(node->vpt); node->flags.needs_resolving = tmpl_needs_resolving(node->vpt); + /* don't merge flags. That will happen when the node is added to the head */ + /* - * Don't keep an intermediate tmpl. + * Don't call tmpl_resolve() here, it should be called + * in pass2 or later during tokenization if we've managed + * to resolve all the operands in the expression. + */ + + fr_sbuff_skip_whitespace(&our_in); + + /* + * Do various tmpl fixups. + */ + + /* + * Don't keep an intermediate tmpl for xlats. Just hoist + * the xlat to be a child of this node. */ if (tmpl_contains_xlat(node->vpt)) { xlat_exp_head_t *xlat = tmpl_xlat(node->vpt); @@ -1137,23 +1165,6 @@ static ssize_t tokenize_field(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_ node->flags = xlat->flags; } - /* don't merge flags. That will happen when the node is added to the head */ - - /* - * It would be nice if tmpl_afrom_substr() did this :( - */ - if (quote != T_BARE_WORD) { - if (!fr_sbuff_is_char(&our_in, fr_token_quote[quote])) { - fr_strerror_const("Unterminated string"); - fr_sbuff_advance(&our_in, slen * -1); - goto error; - } - - fr_sbuff_advance(&our_in, 1); - } - - fr_sbuff_skip_whitespace(&our_in); - /* * Try and add any unknown attributes to the dictionary * immediately. This means any future references point @@ -1165,13 +1176,14 @@ static ssize_t tokenize_field(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_ goto error; } - /* - * Don't call tmpl_resolve() here, it should be called - * in pass2 or later during tokenization if we've managed - * to resolve all the operands in the expression. - */ - - fr_sbuff_skip_whitespace(&our_in); + if (tmpl_is_data(vpt)) { + /* + * Print "true" and "false" instead of "yes" and "no". + */ + if ((tmpl_value_type(vpt) == FR_TYPE_BOOL) && !tmpl_value_enumv(vpt)) { + tmpl_value_enumv(vpt) = attr_expr_bool_enum; + } + } done: #ifdef __clang_analyzer__ diff --git a/src/tests/unit/xlat/cond_base.txt b/src/tests/unit/xlat/cond_base.txt index 55fbcd6c214..f531fa5bce6 100644 --- a/src/tests/unit/xlat/cond_base.txt +++ b/src/tests/unit/xlat/cond_base.txt @@ -281,16 +281,15 @@ match ERROR offset 12: Missing separator, expected ':' # # Tests for boolean data types. # -# @todo - we probably want this to use "true", too. xlat_purify true -match yes +match true -# @todo - for conditions, this should evaluate to "yes" +# @todo - for conditions, this should evaluate to "true" xlat_purify 1 match 1 xlat_purify false -match no +match false xlat_purify 0 match 0 @@ -299,17 +298,17 @@ match 0 # @todo - purify logical operators. The instantiation function should update the "can_purify" flags. # xlat_purify true && (&User-Name == "bob") -match (yes && (&User-Name == "bob")) +match (true && (&User-Name == "bob")) #match &User-Name == "bob" xlat_purify false && (&User-Name == "bob") -match (no && (&User-Name == "bob")) +match (false && (&User-Name == "bob")) xlat_purify false || (&User-Name == "bob") -match (no || (&User-Name == "bob")) +match (false || (&User-Name == "bob")) xlat_purify true || (&User-Name == "bob") -match (yes || (&User-Name == "bob")) +match (true || (&User-Name == "bob")) # # Both sides static data with a cast: evaluate at parse time. @@ -389,10 +388,10 @@ xlat_purify (0) match 0 xlat_purify (true) -match yes +match true xlat_purify (false) -match no +match false xlat_purify ('') match '' @@ -679,10 +678,10 @@ match false # More short-circuit evaluations # xlat_purify (&User-Name == "bob") && (false) -match ((&User-Name == "bob") && no) +match ((&User-Name == "bob") && false) xlat_purify (&User-Name == "bob") || (true) -match ((&User-Name == "bob") || yes) +match ((&User-Name == "bob") || true) # # A && (B || C) is not the same as (A && B) || C, for 0/1/1