allthingssecurity opened a new pull request, #29044: URL: https://github.com/apache/camel/pull/29044
# Description [CAMEL-26420](https://issues.apache.org/jira/browse/CAMEL-26420) Follow-up of CAMEL-26312 (#28715), which left `join` out on purpose. `JoinFunctionFactory` split the arguments of `${join(separator,prefix,exp)}` with `StringQuoteHelper.splitSafeQuote(values, ',', false)`, which keeps the white space around a value, so a space after a comma became part of the next argument: ``` body: [A, B, C] ${join(&,id=)} -> id=A&id=B&id=C ${join(&, id=)} -> " id=A& id=B& id=C" (the prefix was " id=") ${join(&, id=, ${header.ids})} -> the expression was " ${header.ids}" ``` ## The fix (option (b) of the JIRA) - The prefix and the expression are now read as `SimpleFunctionHelper.splitArguments` reads the arguments of the collection functions (CAMEL-24969) and of `replace`, `substring`, ... (CAMEL-26312): no white space around them, spaces inside quotes kept, the quotes around a whole argument removed. - An unquoted separator is kept as written: `${join(; )}` still joins with `"; "`, and `${join(; ,id=)}` too. Trimming it as well (option (a)) would change separators that mix text and spaces, such as `; ` or ` | `, which work today (an argument of only white space is kept by `splitArguments` anyway), and fix no bug in return; if you prefer (a), it is a one-line change plus an upgrade-guide sentence. Note that `concat` and `pad` trim their separator, so the separator of `join` is the only separator argument whose outer white space is kept. - A quoted separator is the text inside its quotes (`${join('&' ,id=)}` joins with `&`; it joined with `"& "`). - One split: the arguments as written are split with `splitSafeQuote(values, ',', false, true)`, the split `splitArguments` uses; the separator only loses the quotes around it, and the prefix and the expression go through the new `SimpleFunctionHelper.trimArgument`, which `splitArguments` now uses for each argument (the same code, moved into a method). Without quotes, the separator is exactly what it was before (a random comparison of main and the branch over many short inputs: no difference). Only the quotes around a whole argument are removed now, also for the separator, as for the other functions since CAMEL-26312: a quote inside an argument is kept (the old split removed every quote): `${join(&,a'b'c)}` uses the prefix `a'b'c` (it was `abc`), and an expression such as `${join(&,id=,${header.x.split(',')})}` now works (on main the quotes were removed, the expression became `split(,)` and failed with an `AmbiguousMethodCallException`). The guide names both. Not changed (on main as well): an empty argument is dropped (`${join(,id=)}` uses `id=` as the separator), and a comma inside a nested function splits the argument (`${join(&,id=,${substring(1,2)})}` is refused). Both are in the split that all functions using `splitArguments` share (`${replace(b,,${header.s})}`, `${replace(b,${header.s.substring(1,3)})}` behave the same), so they need one fix for all of them; `${join(,,)}` fails with an index error instead of the syntax message, and `${join( )}` gives the default separator. Follow-up: CAMEL-26465. Docs: `simple-functions.adoc` (and its catalog copy) says it next to the `join` examples; the 4.24 upgrade-guide paragraph is folded into the existing "Simple: a space after a comma is not part of a function argument" section of CAMEL-26312. ## Tests `JoinFunctionFactoryTest` (camel-core) +3: - `join(&, id=)`, `join(&, id= )`, `join(&, id=, ${header.id})`, `join('&', 'id=', '${header.id}')` give the values without the spaces; `join(&,' id=')` keeps the quoted space; - the separator kept as written: `join(; )` and `join(; ,id=)` give `A; B; C` / `id=A; id=B; id=C` (controls, as before), and `join('; ', id=)` gives `id=A; id=B; id=C`; - quotes inside an argument kept: `join(&,a'b'c)`, `join(&,id=,${header.x.split(',')})`, and the quoted separator `join('&' , id=)`. With main's `JoinFunctionFactory` the 3 new tests fail (the separator test on its last assertion; its first two are controls); with the separator trimmed too (option (a)), the separator test fails. The two existing tests (the documented examples) pass unchanged. A random comparison of main and the branch over 300k inputs: for inputs without quotes the separator is the same as on main and the prefix and expression are main's values trimmed; no input that main accepted is refused now. - The test class 20 times in one JVM: 100 tests, 0 failures. - camel-core `org.apache.camel.language.simple.**`, the other Simple and function tests: 728 tests, 9 failures, all also with main's `JoinFunctionFactory` (OGNL syntax-hint tests in `SimpleSyntaxHintsTest` and `SimpleTest` that fail locally because of a stale camel-bean jar in the local repository; unrelated). - Formatter and import-sort: no changes. # 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-26420) filed for the change (usually before you start working on it): [CAMEL-26420](https://issues.apache.org/jira/browse/CAMEL-26420). # 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 and ran the tests above, including the formatter and import-sort plugins; the catalog copy of `simple-functions.adoc` is identical to the page. I did not run the full root build.) # 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]
