The $(if ...) function uses strlen to decide if the expanded condition is true. But it only needs to know if the string is not empty, and not the length of the string.
I think it only needs to test if the first character is not nul. This is the change:
1248c1248
< result = strlen (expansion);
---
> result = (*expansion != '\0');
Rob.