From 3728e9a14f401b7181faed45c0790fdd0d5ec4dc Mon Sep 17 00:00:00 2001 From: rosensilva Date: Tue, 29 Aug 2023 14:59:02 +0530 Subject: [PATCH] Fix adding redundant quotation marks for enrich Fixes: https://github.com/wso2/micro-integrator/issues/2944 --- .../apache/synapse/util/InlineExpressionUtil.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/synapse/util/InlineExpressionUtil.java b/modules/core/src/main/java/org/apache/synapse/util/InlineExpressionUtil.java index 78157194b8..bff2ffcbf0 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/InlineExpressionUtil.java +++ b/modules/core/src/main/java/org/apache/synapse/util/InlineExpressionUtil.java @@ -92,6 +92,13 @@ 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; @@ -99,7 +106,7 @@ private static String replaceValue(MessageContext messageContext, String text, b // 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); @@ -107,6 +114,10 @@ private static String replaceValue(MessageContext messageContext, String text, b return text; } + private static boolean isSurroundedByQuotes(String text) { + + return text.startsWith("\"") && text.endsWith("\""); + } /** * Replaces Dynamic Values represented by expressions inside json-eval. *