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

isvariable does not work with array keys containing spaces

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.7.3
    • Component/s: None
    • Labels:
      None

      Description

      isvariable() works on array keys that do not contain spaces:
      <pre>
      bundle agent example
      {
      vars:
      "array[one]" string => "1";

      classes:
      "have_one" expression => isvariable("array[one]");

      reports:
      have_one::
      "Have array key 'one' as expected containing value '$(array[one])'";
      }
      </pre>

      <pre>
      > $ cf-agent -KIf ./array.cf -b example
      2015-04-01T14:39:31-0500 info: Using command line specified bundlesequence
      R: Have array key 'one' as expected containing value '1'
      </pre>

      But it errors on keys that contain spaces.
      <pre>
      bundle agent example
      {
      vars:
      "array[one]" string => "1";
      "array[twenty one]" string => "21";

      classes:
      "have_one" expression => isvariable("array[one]");
      "have_twenty_one" expression => isvariable("array[twenty one]");

      reports:
      have_one::
      "Have array key 'one' as expected containing value '$(array[one])'";
      have_twenty_one::
      "Have array key 'twenty one' as expected containing value '$(array[twenty one])'";
      }
      </pre>
      <pre>
      > $ cf-agent -KIf ./array.cf -b example
      2015-04-01T14:41:42-0500 error: /default/example/classes: Fatal CFEngine error: In function 'isvariable', error in variable 'array[twenty one]', 'Scalar value is out of range'
      2015-04-01T14:41:42-0500 error: Policy failed validation with command '"/home/nickanderson/.cfagent/bin/cf-promises" "./array.cf" -b "example"'
      </pre>

      Sometimes data key or array keys have spaces, we should still be able to check if they are defined.

      I have been able to work around this by using strcmp to check if a key matches a pattern, but its ugly, and probably not a very obvious workaround.

        Attachments

          Activity

            People

            • Assignee:
              a10040 Kristian Amlie
              Reporter:
              a10042 Nick Anderson
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Summary Panel