node-red / node-red-ui-nodes

Additional nodes for Node-RED Dashboard
Apache License 2.0
117 stars 81 forks source link

node-red-node-ui-table not rendered if a single quote character is in the description (info) #66

Open wipfl opened 3 years ago

wipfl commented 3 years ago

Which node are you reporting an issue on?

nod-red-node-ui-table 0.3.10

What are the steps to reproduce?

  1. Place an ui-table on the dashboard and feed it with some content. Make sure that the table shows the wanted content.
  2. Edit the description of the ui-table and enter a single quote character (').
  3. Deploy again. Now the table is not shown anymore. I don't know the exact reason, but somehow a string is send to angular with the full object of the ui-table node. (I can't find the starting single quote!) The single quote character in the info-field of the object terminates this string and then the json lexer can't handle this string anymore. Maybe the stringifier is the base cause. To my opinion this is also the reason for the issue #28

Note: Double quotes don't disturb. Single quotes in the table content are also not an issue.

What happens?

The table is not rendered if a single quote character is in the description (info)

What do you expect to happen?

The table should render. The description should have no influence on the behaviour of the node.

A simple work-around would be to remove the info field from the object for this purpose.

Please tell us about your environment:

Christian-Me commented 3 years ago

``Hi,

thank you for submitting this issue. Actually this effect can be spotted in other ui-nodes (including my own) following the same scheme for placing the HTML code onto the dashboard.

    function HTML(config) {
       var configAsJson = JSON.stringify(config);
       var html = String.raw`
          <input type='hidden' ng-init='init(` + configAsJson + `)'>
        `;
        return html;
    }

@dceejay : I'm not into regex but after googling perhaps this helps ... (but there must be a better solution to correctly escape inverted commas of all kind correctly) - also as this effect only seams to effect values on first level of the config object (in the columns array they work fine) it is perhaps not necessary to replace all ' apostrophes.

    function HTML(config) {
       var configAsJson = JSON.stringify(config).replace(/[\/\(\)\']/g, "&apos;");
       var html = String.raw`
          <input type='hidden' ng-init='init(` + configAsJson + `)'>
        `;
        return html;
    }

(BTW Now as I know that the info parameter is passed to the dashboard I will perhaps be less generous with long markdowns in my UI nodes 😂)

Simply deleting or excluding the config.info property may fix this but the problem appear in widgets with labels too (config.label)