Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-27294

PlatformFunction Fn.htmlEscape not available in JS automation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 10.10
    • Fix Version/s: 11.1
    • Component/s: Automation
    • Backlog priority:
      600
    • Upgrade notes:
      Hide

      The following methods become non-static to be available via JS automation:
      org.nuxeo.ecm.automation.features.PlatformFunctions#htmlEscape
      org.nuxeo.ecm.automation.features.PlatformFunctions#nxqlEscape

      You can use them directly through the `Fn` object:

      var escapedHtml = Fn.htmlEscape(html)
      var escapedNxql = Fn.nxqlEscape(nxql)
      

      When used in Java code, you must update your code from:

      String htmlEscaped = PlatformFunctions.htmlEscape(html);
      String nxqlEscaped = PlatformFunctions.nxqlEscape(nxql);
      

      to:

      PlatformFunctions pf = new PlatformFunctions();
      String nxqlEscaped = pf.nxqlEscape(nxql);
      
      Show
      The following methods become non-static to be available via JS automation: org.nuxeo.ecm.automation.features.PlatformFunctions#htmlEscape org.nuxeo.ecm.automation.features.PlatformFunctions#nxqlEscape You can use them directly through the `Fn` object: var escapedHtml = Fn.htmlEscape(html) var escapedNxql = Fn.nxqlEscape(nxql) When used in Java code, you must update your code from: String htmlEscaped = PlatformFunctions.htmlEscape(html); String nxqlEscaped = PlatformFunctions.nxqlEscape(nxql); to: PlatformFunctions pf = new PlatformFunctions(); String nxqlEscaped = pf.nxqlEscape(nxql);
    • Sprint:
      nxplatform 11.1.15, nxplatform 11.1.16
    • Story Points:
      2

      Description

      PlatformFunction Fn.htmlEscape not available in JS automation

      Reproduce:

      • Create a JS Automation script
      • Set it to:
        function run(input, params) {
          var html = "<html><body>Coucou</body></html>";
          // Use type ahead => this function is supposed to be available
          var escaped = Fn.htmlEscape(html);
          Console.log(escaped);
        }
        
      • Run it (easy way: have JSF, create an Automation Action for Admin in the User Menu. Doing equivalent in Designer takes only one more minute to display a button anywhere)

      Result is Java stack error with:

      Caused by: jdk.nashorn.internal.runtime.ECMAException: TypeError: Fn.htmlEscape is not a function
      

      While it is a PLatforFunction, see here (this is master but it exists in 10.10 of course).

      Work arounds can be:

      • Wrapp the call in a regular automation chain. Very cumbersome:

      wrapper_htmlEscape Automation Chain. Here is its YAML:

      description: "Calling Fn.htmlEscape in JS fails with:\nCaused by: jdk.nashorn.internal.runtime.ECMAException: TypeError: Fn.htmlEscape is not a function\n\nCaller has set the htmlToEscape Context variable to the HTML"
      operations:
        - Context.SetVar:
            name: escapedHtml
            value: "@{Fn.htmlEscape(htmlToEscape)}"
      

      Your script becomes:

      function run(input, params) {
        var html = "<html><body>Coucou</body></html>";
        // Use type ahead => this function is supposed to be available
        //var escaped = Fn.htmlEscape(html);
        // ========================================================
        // Create a Context Var with the HTML string
        ctx.htmlToEscape = JSON.stringify(bodyJSON);
        // WARNING: wrapper_htmlEscape uses this variable. If you change its name, change wrapper_htmlEscape
        RunOperation(null, {'id': "wrapper_htmlEscape"});
        // wrapper_htmlEscape returns the escaped HTML in the  escapedHtml Context var
        escaped = ctx.escapedHtml;
        
        Console.log(escaped);
      }
      

      Another workaround: Use org.nuxeo.ecm.automation.features.PlatformFunctions.htmlEscape (see comment below)

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day
                1d

                  PagerDuty

                  Error rendering 'com.pagerduty.jira-server-plugin:PagerDuty'. Please contact your Jira administrators.