Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-2194

Mustache templates should not be rendered when passed invalid data

    XMLWordPrintable

    Details

    • Platform:
      N/A
    • Steps to reproduce:
      Acceptance/unit test attached

      Description

      When a mustache template is given a data container that does not exist (or uses a function that is supposed to provide a data container that fails) the file should not be rendered.

      I can see in 3.7.x that mustache templates render using datastate() when given invalid data.

      For example templates seem to render when data is provided like this:

      template_data => parsejson(storejson("missing_ns:missing_bundle.missing_data"))
      

      OR

      template_data => mergedata("missing_ns:missing_bundle.missing_data")
      

      OR

      template_data => @(missing_ns:missing_bundle.missing_data),
      

      Of course in all of those cases the variables that are referenced are completely undefined.

      If the template expected the data to be present, then it would have a bunch of variable misses, and the rendering would complete successfully quietly rendering empty strings for those missing variables.

      It seems to me in the case of invalid data being provided these promises should be skipped, or at least failed without actually trying to render the promised file. I think the subtle difference there is that a failure would result in the ability to define classes, but a skip would just be skipped. I do not yet have a strong opinion on if they should be skipped or failed, but I lean toward skipped.

      I wonder if this has something to do with interaction of datastate.

      At least in the cases of

      template_data => mergedata("missing_ns:missing_bundle.missing_data")
      

      and

      template_data => parsejson(storejson("missing_ns:missing_bundle.missing_data"))
      

      and

      template_data => @(missing_ns:missing_bundle.missing_data),
      

      I get access to cfengine vars via {vars.sys.cf_version. I do not get access to those vars if I pass valid data in. So it seems to be that its falling back to providing datastate if the other data is invalid. This is not expected or desired behaviour.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vpodzime Vratislav Podzimek
                Reporter:
                a10042 Nick Anderson
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel