]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
set and print quotes for string values.
authorAlan T. DeKok <aland@freeradius.org>
Wed, 25 May 2022 14:36:18 +0000 (10:36 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 25 May 2022 14:59:54 +0000 (10:59 -0400)
src/lib/unlang/xlat_purify.c
src/lib/unlang/xlat_tokenize.c
src/tests/unit/xlat/purify.txt

index ffecd253144edbed8e804aabfa1de4b95fed5573..872b0ef7fc3049c6684ca34206203cea7f7c5fae 100644 (file)
@@ -37,10 +37,18 @@ static void xlat_value_list_to_xlat(xlat_exp_head_t *head, fr_value_box_list_t *
        while ((box = fr_dlist_pop_head(list)) != NULL) {
                MEM(node = xlat_exp_alloc_null(head));
                node->type = XLAT_BOX;
-               node->fmt = ""; /* @todo - fixme? */
+
                fr_value_box_copy(node, &node->data, box);
                talloc_free(box);
 
+               if (node->data.type == FR_TYPE_STRING) {
+                       node->quote = T_SINGLE_QUOTED_STRING;
+                       node->fmt = node->data.vb_strvalue;
+               } else {
+                       node->quote = T_BARE_WORD;
+                       node->fmt = ""; /* @todo - fixme? */
+               }
+
                xlat_exp_insert_tail(head, node);
        }
 }
@@ -124,7 +132,6 @@ static int xlat_purify_list(xlat_exp_head_t *head, request_t *request)
                        fr_dlist_talloc_free(&group->dlist);
                        node->type = XLAT_GROUP;
                        node->group = group;
-                       node->quote = T_BARE_WORD;
 
                        xlat_value_list_to_xlat(group, &list);
                        break;
index 3553aecd337f3b9c3a85b0e93f47bd370976e922..34dfc07f1265441562a700fb4974d1850a225559 100644 (file)
@@ -1072,6 +1072,7 @@ static void _xlat_debug(xlat_exp_head_t const *head, int depth)
                            node->flags.needs_async ? "need_async" : "",
                            node->flags.pure ? "pure" : "",
                            node->flags.can_purify ? "can_purify" : "");
+               if (node->quote != T_BARE_WORD) INFO_INDENT("quote = %c", fr_token_quote[node->quote]);
 
                switch (node->type) {
                case XLAT_BOX:
@@ -1189,7 +1190,13 @@ ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_head_t const *head, xlat_exp_t
                /*
                 *      @todo - respect node->quote here, too.  Which also means updating the parser.
                 */
-               FR_SBUFF_RETURN(fr_value_box_print, out, &node->data, e_rules);
+               if (node->quote == T_BARE_WORD) {
+                       FR_SBUFF_RETURN(fr_value_box_print, out, &node->data, e_rules);
+               } else {
+                       FR_SBUFF_IN_CHAR_RETURN(out, fr_token_quote[node->quote]);
+                       FR_SBUFF_RETURN(fr_value_box_print, out, &node->data, fr_value_escape_by_quote[node->quote]);
+                       FR_SBUFF_IN_CHAR_RETURN(out, fr_token_quote[node->quote]);
+               }
                goto done;
 
        case XLAT_TMPL:
index f17346b0dec3660052245627a724d0569ce7bc0c..05f9713f0057585af20bd08341400bd25d3c77ae 100644 (file)
@@ -166,7 +166,7 @@ match (%{Service-Type} == 3)
 #  one value-box, and perhaps it isn't?
 #
 xlat_purify &Filter-Id == ("foo" + "bar")
-match (%{Filter-Id} == foobar)
+match (%{Filter-Id} == 'foobar')
 
 xlat_purify !&User-Name
 match !%{User-Name}