Skip to content

Commit

Permalink
Fix adding redundant quotation marks for enrich
Browse files Browse the repository at this point in the history
  • Loading branch information
rosensilva committed Aug 29, 2023
1 parent 9975c5e commit 3728e9a
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,32 @@ private static String replaceValue(MessageContext messageContext, String text, b
Matcher matcher = EXPRESSION_PATTERN.matcher(text);
while (matcher.find()) {
String matchSeq = matcher.group();
String surroundedString;
try {
surroundedString = text.substring(text.indexOf(matchSeq) - 1, text.indexOf(matchSeq) + matchSeq
.length() + 1);
} catch (Exception e) {
surroundedString = StringUtils.EMPTY;
}
String value = getDynamicValue(messageContext, matchSeq.substring(1, matchSeq.length() - 1));
if (value == null) {
value = StringUtils.EMPTY;
}
// If the string is neither XML or JSON, it is considered a String and must be wrapped in double quotes
// If it is an empty string returned from a json-eval expression it must be wrapped in double quotes
if (isInline && ((value.isEmpty() && matchSeq.contains(EXPRESSION_JSON_EVAL))
|| (!isValidXML(value) && !isValidJson(value)))) {
|| (!isValidXML(value) && !isValidJson(value) && !isSurroundedByQuotes(surroundedString)))) {
value = "\"" + value + "\"";
}
text = text.replace(matchSeq, value);
}
return text;
}

private static boolean isSurroundedByQuotes(String text) {

return text.startsWith("\"") && text.endsWith("\"");
}
/**
* Replaces Dynamic Values represented by expressions inside json-eval.
*
Expand Down

0 comments on commit 3728e9a

Please sign in to comment.