From f702d3ba6b3ce482639b21153b4194ceefd06983 Mon Sep 17 00:00:00 2001 From: Nick Anderson Date: Mon, 5 Jan 2026 16:21:34 -0600 Subject: [PATCH] Test that findfiles() returns directories with a trailing slash when given a trailing slash Prior to findfiles() fixes related to https://cfengine.com/blog/2025/change-in-behavior-findfiles/ findfiles() would return a trailing slash for directories when one was provided. This behavior was expected by users, but not tested for explicitly nor documented as an explicit behavior. Ticket: CFE-4623 Changelog: None --- .../01_vars/02_functions/CFE-4623.cf | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/acceptance/01_vars/02_functions/CFE-4623.cf diff --git a/tests/acceptance/01_vars/02_functions/CFE-4623.cf b/tests/acceptance/01_vars/02_functions/CFE-4623.cf new file mode 100644 index 0000000000..b4598f32a5 --- /dev/null +++ b/tests/acceptance/01_vars/02_functions/CFE-4623.cf @@ -0,0 +1,44 @@ +####################################################### +# +# Test that findfiles() returns trailing slash on directories when a trailing +# slash is provided as input +# +####################################################### + +body common control +{ + inputs => { "../../default.cf.sub" }; + bundlesequence => { default("$(this.promise_filename)") }; +} + +bundle agent test +{ + meta: + "test_soft_fail" string => "cfengine_3_21_8|cfengine_3_24_0|cfengine_3_24_1|cfengine_3_24_2|cfengine_3_24_3|cfengine_3_27_0", + meta => { "CFE-4623" }; + + vars: + "find_this_promise_dirname" + slist => findfiles( "$(this.promise_dirname)/"); +} + +bundle agent check +{ + classes: + + "ok" + expression => regcmp( ".*[\\]$", $(test.find_this_promise_dirname) ); + # Windows uses backslash, so a better regular expression accounting for + # that might be ".*[\\\/]$" + + reports: + ok:: + "$(this.promise_filename) Pass"; + + ok.(verbose_mode|inform_mode):: + "test.find_this_promise_dirname ($(test.find_this_promise_dirname)) has a trailing slash"; + + !ok:: + "$(this.promise_filename) FAIL"; + +}