static xlat_arg_parser_t const xlat_func_cast_args[] = {
{ .required = true, .single = true, .type = FR_TYPE_VOID },
- { .required = true, .type = FR_TYPE_VOID },
+ { .type = FR_TYPE_VOID },
{ .variadic = XLAT_ARG_VARIADIC_EMPTY_KEEP, .type = FR_TYPE_VOID },
XLAT_ARG_PARSER_TERMINATOR
};
}
}
+ (void) fr_value_box_list_pop_head(args);
+
+ /*
+ * When we cast nothing to a string / octets, the result is an empty string/octets.
+ */
+ if (unlikely(!fr_value_box_list_head(args))) {
+ if ((type == FR_TYPE_STRING) || (type == FR_TYPE_OCTETS)) {
+ fr_value_box_t *dst;
+
+ MEM(dst = fr_value_box_alloc(ctx, type, NULL, false));
+ fr_dcursor_append(out, dst);
+
+ return XLAT_ACTION_DONE;
+ }
+
+ RDEBUG("No data for cast to '%s'", fr_type_to_str(type));
+ return XLAT_ACTION_FAIL;
+ }
+
/*
* Cast to string means *print* to string.
*/
fr_sbuff_t *agg;
fr_value_box_t *dst;
- (void) fr_value_box_list_pop_head(args);
talloc_free(name);
FR_SBUFF_TALLOC_THREAD_LOCAL(&agg, 256, SIZE_MAX);
/*
* Copy inputs to outputs, casting them along the way.
*/
- arg = name;
+ arg = NULL;
while ((arg = fr_value_box_list_next(args, arg)) != NULL) {
fr_value_box_t *vb, *p;
--- /dev/null
+&request += {
+ &Tmp-IP-Address-0 = 192.0.2.1
+ &Tmp-IP-Address-0 = 192.0.2.2
+ &Tmp-IP-Address-0 = 192.0.2.3
+ &Tmp-IP-Address-0 = 192.0.2.4
+}
+
+if (%{Tmp-IP-Address-0[#]} != 4) {
+ test_fail
+}
+
+#
+# This expansion should succeed, and should result in an empty string.
+#
+# It's stupid to do this expansion. The admin should instead just check
+# for the existence of the attribute. But... the syntax allows it, so
+# it should work.
+#
+if !("%{Tmp-IP-Address-0[4]}" == '') {
+ test_fail
+}
+
+success