]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
print "true" and "false" in more situations
authorAlan T. DeKok <aland@freeradius.org>
Fri, 27 May 2022 19:01:46 +0000 (15:01 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 3 Jun 2022 11:15:43 +0000 (07:15 -0400)
src/lib/unlang/xlat_expr.c
src/tests/unit/xlat/cond_base.txt

index ee19cfc128e55253885e21caf2e8a877c6f38d4d..f3d0302d4dfcd5dc4442e47e732f69de837bc77d 100644 (file)
@@ -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__
index 55fbcd6c21499bd66f52400f56cf348f8b4885b7..f531fa5bce6cdf85db93809cc2da63c1f1f9d9b7 100644 (file)
@@ -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