camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Incorrect string replacement order in Camel SNMP?
Date Sat, 03 Oct 2015 05:52:30 GMT
Hi

Thanks for spotting. You are welcome to log a JIRA and work on a PR or patch.
http://camel.apache.org/contributing

On Sat, Oct 3, 2015 at 3:06 AM, Dmitry Zolotukhin <zlogic@gmail.com> wrote:
> Hi,
>
> In Camel SNMP, the org.apache.camel.component.snmp.SnmpConverters
> class has a static “getXmlSafeString” method which escapes unsafe
> characters by replacing them. However, the order of applying
> replacements is not correct:
>
>     private static String getXmlSafeString(String string) {
>
>         return string.replaceAll("<", "&lt;").replaceAll(">",
> "&gt;").replaceAll("&", "&amp;").replaceAll("\"",
> "&quot;").replaceAll("'", "&apos;");
>
>     }
>
>
> It replaces “<” with “&lt;” at first, then the “&” is replaced
with
> “&amp;”. This means that a “<” character in the input string will be
> changed to “&lt;”, and then into “&amp;lt;”, which is not the intended
> behavior.
>
> This could be fixed by applying the “replaceAll("&", "&amp;")”
> transformation first.
>
> --
> Best regards,
> Dmitry



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition:
https://www.manning.com/books/camel-in-action-second-edition

Mime
View raw message