From: Alan T. DeKok Date: Sat, 29 Mar 2025 23:52:01 +0000 (-0400) Subject: %map() returns bool, not int8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b423f944d0d684cd723a1532c617aa426f14ef8;p=thirdparty%2Ffreeradius-server.git %map() returns bool, not int8 and isn't it really %eval(), but with assignment? The normal %eval() evaluates conditions and expressions. --- diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index 8b4c0a82d36..cca7a5dfd06 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -1270,8 +1270,8 @@ static xlat_action_t xlat_func_map(TALLOC_CTX *ctx, fr_dcursor_t *out, return XLAT_ACTION_FAIL; } - MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_INT8, NULL)); - vb->vb_int8 = 0; /* Default fail value - changed to 1 on success */ + MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_BOOL, NULL)); + vb->vb_bool = false; /* Default fail value - changed to true on success */ fr_dcursor_append(out, vb); switch (map->lhs->type) { @@ -1306,7 +1306,7 @@ static xlat_action_t xlat_func_map(TALLOC_CTX *ctx, fr_dcursor_t *out, talloc_free(map); if (ret < 0) return XLAT_ACTION_FAIL; - vb->vb_int8 = 1; + vb->vb_bool = true; return XLAT_ACTION_DONE; } @@ -4296,7 +4296,7 @@ do { \ XLAT_REGISTER_PURE("bin", xlat_func_bin, FR_TYPE_OCTETS, xlat_func_bin_arg); XLAT_REGISTER_PURE("hex", xlat_func_hex, FR_TYPE_STRING, xlat_func_hex_arg); - XLAT_REGISTER_PURE("map", xlat_func_map, FR_TYPE_INT8, xlat_func_map_arg); + XLAT_REGISTER_PURE("map", xlat_func_map, FR_TYPE_BOOL, xlat_func_map_arg); XLAT_REGISTER_PURE("md4", xlat_func_md4, FR_TYPE_OCTETS, xlat_func_md4_arg); XLAT_REGISTER_PURE("md5", xlat_func_md5, FR_TYPE_OCTETS, xlat_func_md5_arg); #if defined(HAVE_REGEX_PCRE) || defined(HAVE_REGEX_PCRE2) diff --git a/src/tests/keywords/map-xlat b/src/tests/keywords/map-xlat index a45c6056c27..1087efd948c 100644 --- a/src/tests/keywords/map-xlat +++ b/src/tests/keywords/map-xlat @@ -9,7 +9,7 @@ request += { NAS-Port-Id = "request.Vendor-Specific.Nokia-SR.MSAP-Interface += 'UNICAST_7360OLT4'" } -if (!("%map(%{Filter-Id})" == 1)) { +if !%map(Filter-Id) { test_fail } @@ -18,7 +18,7 @@ if (!(control.Filter-Id == 'testing123')) { } foreach thing (NAS-Port-Id[*]) { - if (%map(thing) != 1) { + if !%map(thing) { test_fail } } diff --git a/src/tests/keywords/map-xlat-nested b/src/tests/keywords/map-xlat-nested index 385a53e939b..85961474171 100644 --- a/src/tests/keywords/map-xlat-nested +++ b/src/tests/keywords/map-xlat-nested @@ -5,7 +5,7 @@ # Filter-Id := "request.Tmp-Group-0.User-Name = 'testing123'" -if (!("%map(%{Filter-Id})" == 1)) { +if !%map(Filter-Id) { test_fail } diff --git a/src/tests/keywords/map-xlat-nested-overwrite b/src/tests/keywords/map-xlat-nested-overwrite index a61ede0b046..fb6ad6fe525 100644 --- a/src/tests/keywords/map-xlat-nested-overwrite +++ b/src/tests/keywords/map-xlat-nested-overwrite @@ -5,15 +5,15 @@ # Filter-Id := "request.Tmp-Group-0.Filter-Id := 'testing123'" -if (!(%map("%{Filter-Id}") == 1)) { +if !%map(Filter-Id) { test_fail } -if (!(%map("%{Filter-Id}") == 1)) { +if !%map(Filter-Id) { test_fail } -if (!(%map("request.Tmp-Group-0.User-Name := 'testing000'") == 1)) { +if !%map("request.Tmp-Group-0.User-Name := 'testing000'") { test_fail } diff --git a/src/tests/keywords/map-xlat-struct b/src/tests/keywords/map-xlat-struct index 5f898b90218..16075031131 100644 --- a/src/tests/keywords/map-xlat-struct +++ b/src/tests/keywords/map-xlat-struct @@ -8,7 +8,7 @@ string test_string test_string := "IA-PD.IAID = 11" -if (!("%map(%{test_string})" == 1)) { +if !%map(test_string) { test_fail }