json-e
json-e copied to clipboard
Empty strings in $default arm of switch operator are treated as null
This can be illustrated with a simple test case:
Example 1:
$switch:
true: ''
$default: ''
Example 2:
$switch:
false: ''
$default: ''
Here example 1 evaluates to ''
, and example 2 evaluates to null
. I would expect them both to evaluate to an empty string.
This bug is made a bit worse by the fact that json-e
omits the result of a switch
operator from the parent container if it evaluates to null
. Here's the (simplified) real world example where this was causing problems:
command:
$let:
extraArgs:
$switch:
'condition': '--extra'
$default: ''
in: >
command --arg ${extraArgs}
Setting condition
to false in the above example, results in:
# InterpreterError at template.command: unknown context value extraArgs