String header = "EXL=TST+[Placeholder1]+[Placeholder2]+[Placeholder3]:[Placeholder2]"
header = header.replaceAll("\\[Placeholder1\\]", escapeEdi((String)${propertyVal1}))
header = header.replaceAll("\\[Placeholder2\\]", escapeEdi((String)${propertyVal2}))
header = header.replaceAll("\\[Placeholder3\\]", escapeEdi((String)${propertyVal3}))
println(header)
String escapeEdi(String target){
StringBuilder result = new StringBuilder();
for(char c : target.toCharArray()){
switch(c){
case '+':
case ':':
case '\'':
case '?':
result.append("?");
default:
result.append(c);
}
}
return result.toString();
}
With the above sample code, I'm getting the payload result with a lot of question marks within it:
Example payload:
EXL=TST+1+?1234?+1234+123?:123?+?1-1-170101?++?TEST?'
Even removing the escapeEdi function nets the exact same result. I'm not even sure if the escape edi is needed, and frankly none of the values passed have any such characters, purely alphanumeric.
Because of the ?, it's causing the message to be sent with a UTF-8-BOM, and their end is just not designed to handle it, which means it must be cleared and removed on my end. How can I get rid of all these ?
A simple replaceAll with an empty string didn't work. Trying to escapeEdi() at the end of the result didn't do anything either, and I have a very similar script to this which works just fine, no silly character included. What might be causing this issue?
the funny thing )
the following code
String header = "EXL=TST+[Placeholder1]+xxx"
header = header.replaceAll("\\[Placeholder1\\]", "val1")
println header
produces
EXL=TST+?val1?+xxx
and finally i found that there is a strange spaces before and after []
in your source string with uni-code value (8203)
and it is Unicode Character 'ZERO WIDTH SPACE' (U+200B)
see on the screenshot in green: