shashank created CAMEL-26308:
--------------------------------

             Summary: camel-core-languages - Simple iif and val return a quoted 
literal with its quotes: ${iif(${header.foo} > 0,'positive','negative')} gives 
'positive', not positive
                 Key: CAMEL-26308
                 URL: https://issues.apache.org/jira/browse/CAMEL-26308
             Project: Camel
          Issue Type: Bug
          Components: camel-core
            Reporter: shashank
            Assignee: shashank


{{iif}} was added in CAMEL-21081 (4.8.0) with tests where quoted true and false 
values give the text inside the quotes ({{${iif(${header.foo} > 
0,'positive','negative')}}} -> {{positive}}). Since CAMEL-22204 (4.10.7, 
4.13.0) the arguments of {{iif}} are split with 
{{StringQuoteHelper.splitSafeQuote(values, ',', true, true)}} (today in 
{{MiscFunctionFactory}}), keeping the quotes, so that a quoted value in the 
predicate ({{${file:name} startsWith 'test'}}) survives. The true and false 
values keep them as well, and each is then a Simple expression whose text 
includes the quotes. {{val}} (CAMEL-23047, 4.18.1) has passed its argument on 
with the quotes since it was added. So:

{noformat}
${iif(${header.foo} > 0,'positive','negative')}   -> 'positive'    (the 
documented example; before 4.10.7: positive)
${header.foo > 0 ? 'positive' : 'negative'}       -> positive      (the ternary 
operator)
${iif(${header.foo} > 0,'yes','no')} == 'yes'     -> false         (when foo > 
0)
${val('Hello')}                                    -> 'Hello'
{noformat}

The Simple functions page gives the {{iif}} example with quoted values and says 
the same example is used with the ternary operator, whose section says it 
returns {{positive}}; the catalog examples ({{SimpleConstants}}) say 
{{${iif(${header.admin} == true,'Admin','User')} -> Admin}} and 
{{${val('Hello')} -> Hello}}. csimple (removed in 4.23) returned the text 
without the quotes for both functions.

The PR of CAMEL-22204 (#18483) argued that quotes should be a legal part of the 
true and false expressions and changed the existing {{testIif}} assertions to 
unquoted values; {{MiscFunctionFactoryTest}} (CAMEL-22894) later pinned the 
quoted result ({{'yes'}}), in the same commit that pinned the csimple code for 
the same input to {{"yes"}}. So the quoted result may be seen as intended; this 
issue proposes the documented behaviour instead, because it is what the docs, 
the catalog, the ternary operator, the original tests and the other functions 
(such as {{concat}}) do with a quoted argument. If the quoted result is 
preferred, the docs and the catalog examples need fixing instead.

*Fix*: remove the leading and ending quotes of the true and false values of 
{{iif}} ({{StringHelper.removeLeadingAndEndingQuotes}}, as {{concat}} does with 
its arguments) and of the argument of {{val}}. The predicate keeps its quotes; 
values without quotes and functions are unchanged. Upgrade guide entry for 
users who removed the quotes themselves or relied on them.

*Tests*: {{SimpleTest.testIifQuotedLiterals}} (the documented example next to 
the ternary, a double-quoted value, a value with a comma, an empty value, iif 
in a template and in a predicate, a function inside the quotes, val inside iif, 
a quoted predicate), {{StringFunctionFactoryTest.testValQuotedLiteral}}, and 
{{MiscFunctionFactoryTest.testIifTrue/False}} now expect {{yes}} / {{no}}: the 
four fail on main and pass with the fix.

*How it was found*: running every example of the Simple catalog metadata 
({{SimpleConstants}}, "expression -> result") through the language and 
comparing with the documented result; {{iif}} and {{val}} differ on quotes. The 
other differences are context-dependent examples or documentation slips, not 
changed here: {{concat('Hello',' ','World')}} uses the third argument as the 
separator and gives {{HelloWorld }}, and {{date-with-timezone(...)}} is written 
{{date-with-timezone:...}}.

*Affected*: {{iif}} in 4.10.7 and later 4.10.x, 4.13.0 and later; {{val}} in 
4.18.1 and later; main (read, and run on main).

_Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to