]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
omit printing a union if it has only one child.
authorAlan T. DeKok <aland@freeradius.org>
Tue, 28 Oct 2025 13:06:35 +0000 (09:06 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 28 Oct 2025 13:07:54 +0000 (09:07 -0400)
this simplifies the output and makes it easier to understand.
it's also the counterpart to adding the ALIAS which points from
the parent of the union, to the union member.

Other parts of the server will need to be updated to omit unions,
too.  But for now, this is good enough for tests.

src/lib/util/pair_print.c
src/tests/unit/protocols/radius/union.txt

index 10bf684302e8a52f9afd11055947aa2cb226086f..75412ac5897373feaaae2f30b1385a1d032946b5 100644 (file)
@@ -121,6 +121,15 @@ ssize_t fr_pair_print(fr_sbuff_t *out, fr_dict_attr_t const *parent, fr_pair_t c
 
        PAIR_VERIFY(vp);
 
+       /*
+        *      Omit the union if we can.
+        */
+       if ((vp->vp_type == FR_TYPE_UNION) &&
+           (fr_pair_list_num_elements(&vp->vp_group) == 1)) {
+               parent = vp->da;
+               vp = fr_pair_list_head(&vp->vp_group);
+       }
+
        if ((vp->op > T_INVALID) && (vp->op < T_TOKEN_LAST)) {
                token = fr_tokens[vp->op];
        } else {
@@ -143,7 +152,9 @@ ssize_t fr_pair_print(fr_sbuff_t *out, fr_dict_attr_t const *parent, fr_pair_t c
 
                FR_SBUFF_IN_CHAR_RETURN(&our_out, ':', ':');
                FR_SBUFF_IN_STRCPY_RETURN(&our_out, name);
+
        } else {
+
        no_enumv:
                FR_SBUFF_RETURN(fr_pair_print_value_quoted, &our_out, vp, T_DOUBLE_QUOTED_STRING);
        }
index bec9babdda899619c383826d361562191af127a7..601e94d6ed41db82f646307dc43f51d817ecc903 100644 (file)
@@ -18,7 +18,7 @@ fuzzer-out radius
 #  attribute "truncated" of type bool.
 #
 decode-pair fd 04 01 21
-match Test-Struct2 = { Key-Field = ::Sub-Struct, Data = { Sub-Struct = { Nested-Uint1 = 33 } } }
+match Test-Struct2 = { Key-Field = ::Sub-Struct, Sub-Struct = { Nested-Uint1 = 33 } }
 #match raw.Test-Struct2 = 0x0121
 
 #
@@ -33,7 +33,7 @@ match fd 05 01 21 00
 #  @todo - perhaps we want an internal attribute for "extra" data, of type octets?
 #
 decode-pair fd 06 01 21 12 33
-match Test-Struct2 = { Key-Field = ::Sub-Struct, Data = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } } }
+match Test-Struct2 = { Key-Field = ::Sub-Struct, Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } }
 
 encode-pair -
 match fd 05 01 21 12
@@ -42,7 +42,7 @@ match fd 05 01 21 12
 #  Just right.
 #
 decode-pair fd 05 01 21 12
-match Test-Struct2 = { Key-Field = ::Sub-Struct, Data = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } } }
+match Test-Struct2 = { Key-Field = ::Sub-Struct, Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } }
 
 encode-pair -
 match fd 05 01 21 12
@@ -50,14 +50,14 @@ match fd 05 01 21 12
 #
 #  Without Key-Field - it automatically figures it out
 #
-encode-pair Test-Struct2 = { Data = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } } }
+encode-pair Test-Struct2 = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } }
 match fd 05 01 21 12
 
 #
 #  Skip the UNION
 #
 pair Test-Struct2 = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } }
-match Test-Struct2 = { Data = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } } }
+match Test-Struct2 = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } }
 
 encode-pair Test-Struct2 = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } }
 match fd 05 01 21 12
@@ -67,11 +67,11 @@ match fd 05 01 21 12
 #
 #  @todo - to we want to update the parser to disallow bare key fields like this?
 #
-encode-pair Test-Struct2 = { Key-Field = 2, Data = { Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } } }
+encode-pair Test-Struct2 = { Key-Field = 2, Sub-Struct = { Nested-Uint1 = 33, Nested-Uint2 = 18 } }
 match fd 05 01 21 12
 
 decode-pair fd 05 02 43 41
-match Test-Struct2 = { Key-Field = ::CC, Data = { CC = "CA" } }
+match Test-Struct2 = { Key-Field = ::CC, CC = "CA" }
 
 encode-pair -
 match fd 05 02 43 41