diff --git a/libpromises/rlist.c b/libpromises/rlist.c index 829b1ca254..e25ef5c0f5 100644 --- a/libpromises/rlist.c +++ b/libpromises/rlist.c @@ -913,6 +913,12 @@ static int LaunchParsingMachine(const char *str, Rlist **newlist) { current_state = ST_ELM2; } + else if (CLASS_BRA2(*s)) + { + /* A trailing comma, as in { "a", }. Two commas in a row + * still fall through to the catch-all below. */ + current_state = ST_PRECLOSED; + } else if (CLASS_ANY6(*s)) { current_state = ST_ERROR; diff --git a/tests/acceptance/08_commands/01_modules/module_allows_trailing_comma.cf b/tests/acceptance/08_commands/01_modules/module_allows_trailing_comma.cf index 4e294a877e..3fe18974c4 100644 --- a/tests/acceptance/08_commands/01_modules/module_allows_trailing_comma.cf +++ b/tests/acceptance/08_commands/01_modules/module_allows_trailing_comma.cf @@ -14,9 +14,12 @@ body common control bundle agent test { meta: + "description" -> { "CFE-2140", "redmine7578" } + string => "Test that modules are allowed to define lists with trailing commas"; + "test_soft_fail" - string => "any", - meta => { "redmine7578" }; + string => "windows", + meta => { "ENT-10257" }; commands: "$(G.cat)" diff --git a/tests/unit/rlist_test.c b/tests/unit/rlist_test.c index 9703b1394e..9da9319c2c 100644 --- a/tests/unit/rlist_test.c +++ b/tests/unit/rlist_test.c @@ -415,6 +415,21 @@ static struct ParseRoulette 3, " { ' a\"a ', \" b''b \" , ' c\"c ' } "}, { 3, " { ' a,\"a } { ', \" } b','b \" , ' {, c\"c } ' } "}, + /*Single trailing comma */ + { + 1, "{\"a\",}"}, + { + 1, "{'a',}"}, + { + 1, " {\"\",}"}, + { + 1, " {'',}"}, + { + 2, " {\"\",\"\",}"}, + { + 2, " {'','',}"}, + { + 2, " {'',\"\",}"}, { -1, (char *)NULL} }; @@ -465,12 +480,10 @@ static char *PFR[] = { "{'\"\"\",\"}", "{'',\"\",'}", - /* Misplaced commas*/ - "{\"a\",}", + /* Misplaced commas. A single trailing comma is allowed, see PR above */ "{,\"a\"}", "{,,\"a\"}", "{\"a\",,\"b\"}", - "{'a',}", "{,'a'}", "{,,'a'}", "{'a',,'b'}", @@ -480,24 +493,19 @@ static char *PFR[] = { " {,,}", " {,,,}", " {,\"\"}", - " {\"\",}", " {,\"\",}", " {\"\",,}", " {\"\",,,}", " {,,\"\",,}", - " {\"\",\"\",}", " {\"\",\"\",,}", " { \"\" , \"\" , , }", " {,''}", - " {'',}", " {,'',}", " {'',,}", " {'',,,}", " {,,'',,}", - " {'','',}", " {'','',,}", " { '' , '' , , }", - " {'',\"\",}", " {\"\",'',,}", " { '' , \"\" , , }", " { \"\" , '' , , }",