From 68e87c2dcbb855cc4b494dadfac56bd948ca96e0 Mon Sep 17 00:00:00 2001 From: Eduardo Santos Date: Wed, 15 Jan 2025 11:56:16 +0000 Subject: [PATCH] Fixed LCM escape text --- .../service-rule-design.component.ts | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) 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 a87aeee..a4c0019 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('"', '\\"'); } -- GitLab