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

Should not error when datacontainer key contains space

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: 3.15.1, 3.16.0
    • Fix Version/s: 3.12.6, 3.15.3, 3.17.0
    • Component/s: None
    • Labels:
      None
    • Story Points:
      5
    • Found in version (details):
      nightly, 3.15.1

      Description

      Given /tmp/test.json:

      /tmp/test.json
      {
        "thing s": [
          {
            "Title": "DEBIAN",
            "classexpr": "debian"
          },
          {
            "Title": "UBUNTU",
            "classexpr": "ubuntu"
          }
        ]
      }
      

      and test.cf:

      test.cf
      bundle agent main
      {
        vars:
            "e" data => readjson( "/tmp/test.json" );
            "ei" slist => getindices( "e[thing s]" );
      
            "j" data => '{
        "thing s": [
          {
            "Title": "WINDOWS",
            "classexpr": "windows"
          },
          {
            "Title": "UBUNTU",
            "classexpr": "ubuntu"
          }
        ]
            }';
      
          "ji" slist => getindices( "j[thing s]" );
      
          "d[thing s][0][Title]" string => "UBUNTU";
          "d[thing s][0][classexpr]" string => "ubuntu";
          "d[thing s][1][Title]" string => "WINDOWS";
          "d[thing s][1][classexpr]" string => "windows";
      
          "di" slist => getindices( "d[thing s]" );
      
        reports:
            # concat workaround
            # "Classic Array: $(d[thing s][$(di)][Title]) MATCHED classexpr $(d[thing s][$(di)][classexpr])" if => concat("$(d[thing s][$(di)][classexpr])");
      
            "Classic Array: $(d[thing s][$(di)][Title]) MATCHED classexpr $(d[thing s][$(di)][classexpr])" if => "$(d[thing s][$(di)][classexpr])";
      
            # concat workaround
            # "Inline Data Container: $(j[thing s][$(ji)][Title]) MATCHED classexpr $(j[thing s][$(ji)][classexpr])" if => concat("$(j[thing s][$(ji)][classexpr])");
            "Inline Data Container: $(j[thing s][$(ji)][Title]) MATCHED classexpr $(j[thing s][$(ji)][classexpr])" if => "$(j[thing s][$(ji)][classexpr])";
      
            # concat workaround
            # "External Data Container: $(e[thing s][$(ei)][Title]) MATCHED classexpr $(e[thing s][$(ei)][classexpr])" if => concat("$(e[thing s][$(ei)][classexpr])");
            "External Data Container: $(e[thing s][$(ei)][Title]) MATCHED classexpr $(e[thing s][$(ei)][classexpr])" if => "$(e[thing s][$(ei)][classexpr])";
      }
      
      
      The expression `concat("$([thing s][$(di)][classexpr])")` doesn't seem to evaluate properly. This concat() expression was introduced when the "things" in json/cf was something with a space in it like "thing s". Without the concat() a Syntax error will be given for the report line such as this:
      
      

      ./test.cf:8:48: error: Syntax error in context string
      "has $(d[thing s]) class" if => "$(d[thing s])";
      ^
      error: There are syntax errors in policy files
      error: Policy failed validation with command '"/home/craig/.cfagent/bin/cf-promises" -c "./test.cf"'
      error: Failsafe condition triggered. Interactive session detected, skipping failsafe.cf execution.
      error: Error reading CFEngine policy. Exiting...

      
      

      If the "things" is without a space the ifvarclass expression without concat works as expected.

      So it seems there is a problem in either the parser or the evaluator or both.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel