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

Mustache sections can only take a boolean or a container (array or map) value

    XMLWordPrintable

    Details

      Description

      I have an issue with how cfengine handles mustache templates.

      The mustache engine renders sections when the value is a boolean or container.
      This should be different:

      • Render when (key resolves to value AND (value is true OR value is not empty list))
      • This behaviour should be negatable by the '^' section attribute

      As documented on: http://mustache.github.io/mustache.5.html

      Sections
      Sections render blocks of text one or more times, depending on the value of the key in the current context.
      
      A section begins with a pound and ends with a slash. That is, {{#person}} begins a "person" section while {{/person}} ends it.
      
      The behavior of the section is determined by the value of the key.
      
      False Values or Empty Lists
      
      If the person key exists and has a value of false or an empty list, the HTML between the pound and slash will not be displayed.
      

      http://mustache.github.io/#demo

      Handles the mustache_example.json and mustache_example.mustache as expected; without exeptions.

      The following unittest data seems to handle "Context Misses" correctly
      core/tests/unit/data/mustache_sections.json

              {
                  "name": "Context Misses",
                  "data": {},
                  "expected": "[]",
                  "template": "[{{#missing}}Found key 'missing'!{{/missing}}]",
                  "desc": "Failed context lookups should be considered falsey."
              },
      

      The following acceptance test expects the error "Mustache sections can only take a boolean..." to be thrown.
      core/tests/acceptance/10_files/templating/mustache_section.cf

      I have attached a diff. After applying:

      • rebuild dir core/libutils
      • rebuild dir core/libpromises
      • replace/link libpromises.so

        Attachments

        1. mustache_example.cf
          1 kB
        2. mustache_example.json
          0.4 kB
        3. mustache_example.mustache
          0.1 kB
        4. mustache.c.diff
          3 kB

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                rikvermeer Rik Vermeer
              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Summary Panel