Skip to content

Commit

Permalink
empty lists are equal when compared via ==
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Oct 11, 2023
1 parent cb23611 commit 768ec41
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/lib/util/calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,25 @@ int fr_value_calc_list_cmp(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_li
op = T_OP_CMP_EQ;
}

/*
* Both lists are empty, they should be equal when checked for equality.
*/
if ((fr_value_box_list_num_elements(list1) == 0) &&
(fr_value_box_list_num_elements(list2) == 0)) {
switch (op) {
case T_OP_CMP_EQ:
case T_OP_LE:
case T_OP_GE:
invert = !invert;
break;

default:
break;
}

goto done;
}

/*
* Emulate v3. :(
*/
Expand All @@ -2550,8 +2569,9 @@ int fr_value_calc_list_cmp(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_li
}

/*
* No match.
* No match,
*/
done:
fr_value_box_clear(dst);
fr_value_box_init(dst, FR_TYPE_BOOL, NULL, false); // @todo - add enum!
dst->vb_bool = invert;
Expand Down
45 changes: 45 additions & 0 deletions src/tests/keywords/cmp-list-empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Test empty lists, or xlat failures.
#
# {} == {} --> true
#
if !(%test.fail() == %test.fail()) {
test_fail
}

#
# {} != {} --> false
#
if (%test.fail() != %test.fail()) {
test_fail
}

#
# {} <= {} --> true
#
if !(%test.fail() <= %test.fail()) {
test_fail
}

#
# {} < {} --> false
#
if (%test.fail() < %test.fail()) {
test_fail
}

#
# {} >= {} --> true
#
if !(%test.fail() >= %test.fail()) {
test_fail
}

#
# {} > {} --> false
#
if (%test.fail() > %test.fail()) {
test_fail
}

success

0 comments on commit 768ec41

Please sign in to comment.