KB Article #182631

ADVANCED ROUTING: Empty flow variables handling

Problem

There is a change in ST 5.5 in the way the flow/subscription defined variables are evaluated in AR condition checks. If a variable is not defined at all on a subscription level a following evaluation will simply skip it, making some EL expressions to falsely trigger AR.


Consider that for AR trigger condition the following EL expression is defined:


${transfer.target.matches(concat('.*',subscription.attributes['userVars.Sample1'])) ? 1 : 0}


What happens is that for variables that are not defined on a subscription level, that can be compared in the expression above, the evaluation returns TRUE and the route gets executed. The above applies to the following example where the EL is configured with several different values returned from different subscriptions:


${transfer.target.matches(concat('.*',subscription.attributes['userVars.Sample1'])) ? 1 : 0}
${transfer.target.matches(concat('.*',subscription.attributes['userVars.Sample2'])) ? 1 : 0}
${transfer.target.matches(concat('.*',subscription.attributes['userVars.Sample3'])) ? 1 : 0}
${transfer.target.matches(concat('.*',subscription.attributes['userVars.Sample4'])) ? 1 : 0}


In a real life scenario a Subscription might not initialize all the variables based on its purpose thus some of them might end up undefined and consequently skipped by the EL engine. This could lead to the expresion evaluating to TRUE, since the result of concat('.*',subscription.attributes['userVars.Sample2']) will be .* which means "everything". In that case the AR will trigger when it is not supposed to.


Resolution

The workaround here would be to add a test to the expressions to validate that the variables are not empty and return FALSE if they are.


For example:


${empty(subscription.attributes['userVars.Sample2']) ? 0 : transfer.target.matches(concat('.*',subscription.attributes['userVars.Sample1']))}


The outcome of the test can be altered to a different behavior based on the requirements in the particular use case.