allthingssecurity opened a new pull request, #29790:
URL: https://github.com/apache/camel/pull/29790

   # Description
   
   [CAMEL-26886](https://issues.apache.org/jira/browse/CAMEL-26886)
   
   Follow-up of #29126 (CAMEL-26465), named in its description: the same rules 
for the other functions with arguments.
   
   CAMEL-26465 keeps an empty function argument in its place, and does not 
split at a comma inside a nested function, for the functions that split with 
`SimpleFunctionHelper.splitArguments` and for `join`. `concat`, `pad`, 
`convertTo`, `iif`, `hash`, `assert`, `throwException`, `function`, `range`, 
`random` and the math functions (`sum`, `max`, `min`, `average`) still split 
their own way (`StringQuoteHelper.splitSafeQuote`, or `String.split` for 
`range` and `random`):
   - an empty argument was dropped, so the next one took its place: 
`${hash(,SHA3-256)}` hashed the text `SHA3-256` with SHA-256, `${concat(,x,-)}` 
gave `x-`, `${throwException(,java.io.IOException)}` threw an 
`IllegalArgumentException` with the message `java.io.IOException`, and a stray 
comma after the last argument, such as `${iif(p,a,b,)}`, was ignored;
   - a comma inside a nested function split the argument, so `${iif(${header.s} 
== 'a',${header.s.substring(1,3)},no)}`, 
`${concat(${header.s.substring(1,3)},x)}`, 
`${convertTo(${header.n.substring(1,3)},int)}` or 
`${random(${header.min.substring(0,2)},50)}` failed to parse or used the wrong 
pieces.
   
   Change, in the function factories of camel-core-languages: these functions 
split with `SimpleFunctionHelper.splitArgumentsAsWritten`, through a new 
`splitArgumentsKeepQuotes` (trimmed, quotes kept, as these functions remove the 
quotes of some arguments only, such as the predicate of `iif` which keeps them, 
CAMEL-22204). An argument left out means the default where the function has 
one: the message body for the expression of `concat` (first), `convertTo`, 
`hash` and `function`; 0 for the min of `range` and `random`; SHA-256 for the 
algorithm of `hash`; a space for the separator of `pad`, none for `concat`; the 
default exception type of `throwException`. Where it has none it is refused 
(`assert`, `iif`, the message of `throwException`, the type of `convertTo`, the 
expression and width of `pad`, the second expression of `concat`, the name of 
`function`, the max of `range` and `random`). The values of `sum`, `max`, `min` 
and `average` are a list: an empty value is still no value, as b
 efore. The white space around an argument is removed and its quotes are 
handled as before, with two differences: a lone quote at the end of an argument 
is now kept, as for CAMEL-26465 (on main it was dropped, so `${concat(x,')}` 
became the one-argument form); and an argument of only white space is an 
argument left out (on main it was dropped). That second one differs from the 
functions of CAMEL-26465, which keep such an argument as text (`${join( )}` 
joins with a space): these functions always removed that white space, so 
`${concat(a,b, )}` still has no separator and `${pad(${body},5, )}` still pads 
with a space, as on main. The collection functions with a list of values 
(`distinct`, `reverse`, `shuffle`, `list`, `map`) are unchanged. Every form of 
these functions in the documentation and in the camel-core Simple tests parses 
as before.
   
   Docs: the note on function arguments in `simple-functions.adoc` (and its 
catalog copy) now covers every function, with the defaults. 4.24 upgrade guide: 
a section next to the one of CAMEL-26465, with the inputs that now give a 
different result (`${concat(,x,-)}`, `${hash(,SHA3-256)}`) or are refused (an 
argument without a default left out, such as `${concat(x,)}`, and a stray comma 
after the last argument, such as `${iif(p,a,b,)}`), and the way back (remove 
the comma).
   
   Not changed: the docs say `${hash()}` hashes the message body with SHA-256, 
but it is refused, on main and here (`${hash(,)}` now does it). That is a 
separate fix with its own test; I will file a follow-up JIRA for it.
   
   Tests, new `OtherFunctionArgumentsTest` (camel-core):
   - `testCommaInsideANestedFunction`: `concat`, `pad`, `convertTo`, `iif`, 
`function`, `hash`, `sum`, `max`, `range`, `random` and `throwException`, each 
with a nested `substring(1,3)` in an argument;
   - `testArgumentLeftOutWithADefault`: the defaults above;
   - `testArgumentLeftOutWithoutADefaultIsRefused`: 14 inputs of 9 functions 
with an argument left out that has no default;
   - `testEmptyValueOfAMathFunctionIsNoValue` and 
`testQuotesAndSpacesAsBefore`: controls, unchanged behaviour.
   
   Without the change the first three fail on main's function factories, the 
two controls pass. With it the camel-core tests pass (9186 run, 0 failures, 0 
errors, 45 skipped), including the Simple tests of CAMEL-26465; after the last 
review, which only tightened two assertions of the new test, the Simple and 
function factory tests were run again (415 run, 0 failures).
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it): 
[CAMEL-26886](https://issues.apache.org/jira/browse/CAMEL-26886).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     (I built the core modules with the formatter and import-sort plugins and 
ran the camel-core tests. I did not run the full root build; the catalog copy 
of `simple-functions.adoc` is updated by hand to match.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to