LCM Rules - Fixed escape variable

Now, if inside the Escape text block there is a string, the string is correctly escaped. Furthermore, if instead of a string, there is a method inside the block, the method is added to the code inside a new escapeText method to escape the first method returned value.

Screenshot_2025-01-15_at_11.36.06

This escapeText method will then be executed by OSOM (see this). If a user wants to provide as a parameter an array (without using the escape block), the user can use the Get Value as String block, and the value will be sent as is to OSOM, i.e., as an array, string, number, etc. If the user uses the Escape text block, the provided parameter will be escaped and sent as a string.

In the case of the parameter = [{"device": {"ipv4Address": {}, "networkAccessIdentifier": "123456789@domain.com", "phoneNumber": "+123456789"}, "provisioningId": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "qosProfile": "QOS_A", "status": "AVAILABLE", "startedAt": "2024-12-12T09:52:26Z"}]. The final output will be:

Screenshot_2025-01-15_at_11.12.38

Closes #25 (closed)

Edited by Eduardo Santos

Merge request reports

Loading
+31 −11
Changes for src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts: 31 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -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');
  
  // 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('"', '\\"');
}
Loading