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

Maplist over an empty list does not return an empty list

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.7.0
    • Component/s: Built-in functions
    • Labels:
      None

      Description

      It is expected and useful for map functions to return the same size list as what they are given, also when the list is empty. maplist does not return an empty list when given an empty list.

      <pre>
      body common control {
      bundlesequence =>

      { "example" }

      ;
      }

      bundle agent example {
      vars:
      "list" slist => {};
      "mapped_list" slist => maplist("- $(this)", "list");
      "length" int => length("mapped_list");

      classes:
      "length_$(length)" expression => "any";
      "PASS" expression => "length_0";

      reports:
      "mapped_list $(mapped_list)";
      "length $(length)";
      PASS::
      "PASS";
      !PASS::
      "FAIL";
      }
      </pre>

      Actual output:
      <pre>
      R: mapped_list - cf_null
      R: length 1
      R: FAIL
      </pre>

      Expected output:
      <pre>
      R: length 0
      R: PASS
      </pre>

        Attachments

          Activity

            People

            Assignee:
            a10025 Volker Hilsheimer (Inactive)
            Reporter:
            naksu Mr Naksu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: