diff --git a/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts b/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts index a87aeee38c1253c008869b7febc1270f678a450f..a4c0019507f5f5a6d6d6712a46078ba33d3c0edb 100644 --- a/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts +++ b/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts @@ -1169,13 +1169,27 @@ export class ServiceRuleDesignComponent implements OnInit { }; Blockly.Java['text_escape'] = function(block: any) { - var code = Blockly.Java.valueToCode(block, 'paramtxt', - Blockly.Java.ORDER_NONE) || '""'; - code = code.replace('"', ''); - code = code.substring(0, code.length-1); - // code = code.replaceAll('\\', '\\\\'); - // code = code.replaceAll('"', '\\"'); - code = '"' + textEscape(code) + '"'; + + // Get the value connected to 'paramtxt', defaulting to an empty string + var code = Blockly.Java.valueToCode(block, 'paramtxt', Blockly.Java.ORDER_NONE) || '""'; + + // If the code starts and ends with quotes, treat it as a literal string + if (code.startsWith('"') && code.endsWith('"')) { + // Remove surrounding quotes + var literalValue = code.substring(1, code.length - 1); + + // Call the textEscape function to escape the string + literalValue = textEscape(literalValue); + + // Wrap the escaped string in double quotes again + code = '"' + literalValue + '"'; + + return [code, Blockly.Java.ORDER_ATOMIC] + } + + // If the code is not a literal (e.g., it's a method call) + code = "escapeText(" + code + ")"; + return [code, Blockly.Java.ORDER_ATOMIC]; }; @@ -1759,10 +1773,16 @@ export class ServiceRuleDesignComponent implements OnInit { function textEscape(avalue: any): any { - //avalue = avalue.replaceAll('\\', '\\\\'); - avalue = avalue.replaceAll('"', '\\"'); - //avalue = avalue.replaceAll('\\\\\\\\n', '\n'); - - return avalue; + // Check if the value is an object (including arrays) + if (typeof avalue === 'object' && avalue !== null) { + // Convert object or array to a JSON string + avalue = JSON.stringify(avalue); + } else if (typeof avalue !== 'string') { + // If it's not an object/array or string, return as is (e.g., number, null, etc.) + return avalue; + } + + // Escape double quotes in the string + return avalue.replaceAll('"', '\\"'); }