Skip to content

Commit

Permalink
Merge pull request #2096 from rosensilva/master
Browse files Browse the repository at this point in the history
Fix adding redundant quotation marks for enrich
  • Loading branch information
rosensilva authored Feb 8, 2024
2 parents 509df9b + 5ff09ec commit 53609ae
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,33 @@ 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 (IndexOutOfBoundsException e) {
// catch index out of bound exception when the expression is at the beginning or end of the text
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 53609ae

Please sign in to comment.