allthingssecurity opened a new pull request, #28714: URL: https://github.com/apache/camel/pull/28714
# Description [CAMEL-26311](https://issues.apache.org/jira/browse/CAMEL-26311) Since CAMEL-24921 (4.23.0) the braces may hold a predicate. `SimpleSyntaxHints.operatorsOutside` decides whether the text inside `${ }` is one; when it answers null, the text is read as a single function. It answered null for two kinds of predicates: - the operators `equals`, `!equals` (CAMEL-24582), `!startsWith` and `!endsWith` (CAMEL-22868) were not in its list of operator words (and `equals`, `!equals` were not in the list `wrapComparison` uses), so the text was one header name; - a quote anywhere before the operator made it give up, so a function with a quoted argument on the left was created from the text before the operator and the comparison was dropped. ``` ${header.type equals 'gold'} -> null; as a predicate it never matches (header type = gold) ${header.type !startsWith 'si'} -> never matches ${uppercase('a') == 'B'} -> A; as a predicate it always matches ${substringAfter('Hello ') == 'Camel'} -> matches for any body with text after "Hello " ${header.type} equals 'gold' -> true (outside the braces: unchanged) ${header.x == 'y' && uppercase('a') == 'B'} -> false (after && the comparison was already read) ``` The operator page says an operator "can be written inside ${ } or outside it [...] Both mean the same thing". In a `filter` or a `choice` these predicates were silently always false or always true. Changes: - `SimpleSyntaxHints`: the four operators are added to `OPERATOR_WORDS`, and `equals` / `!equals` to `SPACED_OPERATORS`. `operatorsOutside` takes the first operator outside quotes, brackets and parentheses (`indexOutsideQuotes`) instead of returning null when a quote comes before it. Its count of the brackets and parentheses before the operator is removed: `indexOutsideQuotes` already skips an operator in an argument list or a bracket key, and the count also counted a bracket inside quotes (`${replace('(', '[') == 'Hi'}`). An operator inside a quoted argument (`${replace(' == ','=')}`), a property default (`${properties:msg:a == b}`) and a bracket key (`${header[order in progress]}`) are unchanged. - `SPACED_OPERATORS` is also what the condition of a ternary inside the braces is wrapped with, so `${header.type equals 'gold' ? 'a' : 'b'}`, refused before (_Unexpected token header.type_), now works. - Upgrade guide (4.24): `=== camel-core-languages - Simple: more predicates inside ${ } are read as predicates`. This builds on CAMEL-25954 (#28271, on main since 1c94c6ef20aa): only since then does `indexOutsideQuotes` skip brackets and parentheses. Without it the bracket count could not be removed, so a backport to 4.23.x (where CAMEL-24921 is) needs CAMEL-25954 first. Which expressions change: every `${ }` text in apache/camel (main, code, tests, docs) and camel-kamelets 4.23.0, 3 763 distinct ones, gets the same answer from `operatorsOutside` with and without this change: none of them has one of the four operators inside the braces, or a quote before an operator. Tests: - `SimplePredicateInBracesTest`: `testEveryComparisonOperatorInsideTheBraces`, `testFunctionWithAQuotedArgumentOnTheLeft` and `testEqualsInTheConditionOfATernaryInsideTheBraces` fail on main and pass with the change; `testAnOperatorInsideQuotesIsPartOfTheArgument` is a control that passes on both. - Run offline on main as of e4c4dbbeb5da (the date of the local snapshot jars of the other core modules) with the `SimpleSyntaxHints` of origin/main aa63c0a4cb94 (so with CAMEL-25954), then with this change: the three new tests fail without the change; with it, the language tests of camel-core and camel-core-languages (`org/apache/camel/language/**/*Test`, 885 run, 1 skipped) pass, except 8 `SimpleTest` / `SimpleSyntaxHintsTest` methods that came with those test files from later commits to other files and fail the same without this change. The whole camel-core suite, run with this change and the one of the camel-simple-function-argument-spaces branch, gives the same picture (8259 tests, 54 skipped; those 8, and `ValidatorExternalResourceTest`, which needs the network). The formatter and import-sort plugins ran and changed nothing. Backport: main, and 4.23.x (where CAMEL-24921 is) together with CAMEL-25954. How it was found: a readable semantics of the Simple language written from its documentation (Rocq), extracted to an oracle and compared with the language on about 4.9 million generated programs (operators by value kinds, quoting, nested functions, ternary, and/or, null and empty values). This class gave about 24 800 of the disagreements; the same programs agree with this change. The decision of `operatorsOutside` is also checked on the real class files of main and of this change in a JVM model in Rocq (kernel-checked). # 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-26311) filed for the change (usually before you start working on it): [CAMEL-26311](https://issues.apache.org/jira/browse/CAMEL-26311). # 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 ran the tests above with the formatter and import-sort plugins; no option or catalog metadata changed. 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]
