[ 
https://issues.apache.org/jira/browse/CAMEL-24802?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen updated CAMEL-24802:
--------------------------------
    Fix Version/s: 4.23.0

> camel-core - simple: add escape function for html/xml/json/sql/url special 
> characters
> -------------------------------------------------------------------------------------
>
>                 Key: CAMEL-24802
>                 URL: https://issues.apache.org/jira/browse/CAMEL-24802
>             Project: Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 4.23.0
>
>
> A user on Zulip needed to escape special characters (& < > quotes etc.) in 
> message data before feeding it to a Velocity template, and observed that the 
> simple language has no function for this. Today you either chain multiple 
> {{replace(...)}} calls, write a custom bean, or resort to {{${bean:...}}} 
> with a helper class such as Velocity's EscapeTool or commons-text 
> StringEscapeUtils.
> Simple already has {{htmlDecode(exp)}} and {{htmlClean(exp)}} but nothing for 
> the encoding/escaping direction.
> Proposal: add an {{escape(kind,exp)}} function (or {{escapeAs(...)}} / 
> individual functions) covering the common kinds:
> * {{html}} - {{&amp; &lt; &gt; &quot; &#39;}}
> * {{xml}} - the five XML entities
> * {{json}} - backslash-escape quotes, backslashes and control characters
> * {{sql}} - double single quotes
> * {{url}} - percent-encoding (application/x-www-form-urlencoded)
> For example:
> {code}
> ${escape(html, ${body})}
> ${escape(xml, ${header.item})}
> {code}
> The {{exp}} argument should be optional and default to the message body, 
> consistent with the other string functions. The implementation should live in 
> camel-core-languages using JDK-only code (no new dependency), and the 
> function must be documented in simple-functions.adoc and picked up by the 
> TUI/MCP catalog function metadata via the {{@Metadata}} annotation in 
> {{SimpleConstants}}.
> See also the related velocity documentation update that shows how to use 
> Velocity's EscapeTool inside a template as the template-side alternative.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to