You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Dmitry Zolotukhin <zl...@gmail.com> on 2015/10/02 23:31:28 UTC
Incorrect string replacement order in Camel SNMP?
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("<", "<").replaceAll(">", ">").replaceAll("&", "&").replaceAll("\"", """).replaceAll("'", "'");
}
It replaces “<” with “<” at first, then the “&” is replaced with “&”. This means that a “<” character in the input string will be changed to “<”, and then into “&lt;”, which is not the intended behavior.
This could be fixed by applying the “replaceAll("&", "&")” transformation first.