Skip to content

CFE-3105: Made format collect data container - #6223

Open
victormlg wants to merge 1 commit into
cfengine:masterfrom
victormlg:make_format_collecting
Open

CFE-3105: Made format collect data container#6223
victormlg wants to merge 1 commit into
cfengine:masterfrom
victormlg:make_format_collecting

Conversation

@victormlg

Copy link
Copy Markdown
Contributor

No description provided.

}
WriterWrite(w, " }");

BufferAppendF(buf, format_rewrite, StringWriterData(w));
Comment thread libpromises/evalfunction.c Fixed
@victormlg
victormlg force-pushed the make_format_collecting branch from bf0432b to 9667796 Compare July 9, 2026 10:31
Comment thread libpromises/evalfunction.c Fixed
@victormlg
victormlg force-pushed the make_format_collecting branch 8 times, most recently from 3a40ef1 to 10d94b8 Compare July 10, 2026 13:35
Ticket: CFE-3105
Changelog: Title
Signed-off-by: Victor Moene <victor.moene@northern.tech>
@victormlg
victormlg force-pushed the make_format_collecting branch 2 times, most recently from 4374730 to 34a6da4 Compare August 4, 2026 09:25
@victormlg
victormlg marked this pull request as ready for review August 4, 2026 09:25
@victormlg
victormlg requested a review from larsewi August 4, 2026 10:36

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you perhaps use VarNameOrInlineToJson() to achieve this?

@victormlg

victormlg commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Could you perhaps use VarNameOrInlineToJson() to achieve this?

That was my initial idea, however this would break backwards compatibility because string lists are formatted differently from data containers and VarNameOrInlineToJson() parses string lists as data containers.

bundle agent main
{
  vars:
    "stringlist" slist => { "a", "b" };
    "array" data => parsejson('["a", "b"]');
    "str1" string => format("%S", array);
    "str2" string => format("%S", stringlist);

  reports:
    "$(str1)";
    "$(str2)";
}
R: ["a","b"]
R: { "a", "b" } # special case, with current implementation

"key='S_123_list' value='{ \"one\", \"two\", \"\\\"three\\\"\" }'";
"key='S_container_1' value='[null]'";
"key='S_container_2' value='[{\"x\":123},\"yz\"]'";
"key='S_function' value='{\"hello\":\"world\"}'";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must you escape the double quotes? I see it's done there before, but is it required?

"array[S_container_1]" string => format("%S", mycontainer1);
"array[S_container_2]" string => format("%S", mycontainer2);
"formatted" slist => maparray("key='$(this.k)' value='$(this.v)'", "array");
"array[S_function]" string => format("%S", parsejson('{"hello": "world"}'));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should cover a json string directly to illustrate the behavior

"array[S_function]" string => format("%S", '{"hello": "world"}');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants