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

   Fixes https://issues.apache.org/jira/browse/CAMEL-24802
   
   Adds an `escape(kind, exp)` function to the simple language so special 
characters can be escaped without chaining `replace` calls or writing a bean:
   
   ```
   ${escape(html)}                       -> escapes the message body
   ${escape(xml, ${header.title})}
   ${escape(json, ${body})}
   ${escape(js, ${header.msg})}
   ${escape(sql, ${header.name})}
   ${escape(url, 'Camel in Action')}     -> Camel%20in%20Action
   ```
   
   - `kind` is one of `html`, `xml`, `json`, `js` (alias `javascript`), `sql`, 
`url` — case-insensitive, resolved at parse time so an unknown kind fails with 
a `SimpleParserException` listing the valid kinds
   - `exp` is optional and defaults to the message body, like the other string 
functions; only the first comma is used as separator so nested functions with 
commas work (`${escape(html, ${concat(${body},${body},-)})}`)
   - `url` uses RFC 3986 component encoding (space → `%20`, not `+`)
   - Implemented in a new JDK-only `org.apache.camel.util.EscapeHelper` (no new 
dependency); the escape function itself lives in `StringFunctionFactory` / 
`StringExpressionBuilder` in camel-core-languages
   - `@Metadata` on `SimpleConstants` so the function shows up in the catalog, 
the JS validator and the TUI/MCP function reference (regenerated files included)
   - Docs: string function table + a new subsection in `simple-functions.adoc`
   
   Tests: `EscapeHelperTest` (camel-util) and new cases in 
`StringFunctionFactoryTest` (camel-core); ran the full 
`org.apache.camel.language.simple` test package in camel-core (593 tests green).
   
   Background: a user asked on Zulip how to escape special characters before 
feeding data to a Velocity template; the template-side alternative (Velocity 
`EscapeTool`) was documented separately in b2190cda403a.
   
   _Claude Code on behalf of davsclaus_
   


-- 
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