MVC model parsing: it seems that 1e092de495 was a bit too optimistic, checking for empty(string()) only works when the content was pretty printed. When flushing the current config, data isn't formatted and there's not access spacing involved. The proper fix seems to be to always parse the array and if it didn't find any non empty nodes add a template node. closes https://github.com/opnsense/core/issues/4598

This commit is contained in:
Ad Schellevis 2021-01-14 11:29:37 +01:00
parent 166b199de6
commit bbe0f3afe4

View File

@ -235,8 +235,15 @@ abstract class BaseModel
if ($fieldObject->isArrayType()) {
// handle Array types, recurring items
if ($config_section_data != null && !empty((string)$config_section_data)) {
$node_count = 0;
if ($config_section_data != null) {
foreach ($config_section_data as $conf_section) {
if ($conf_section->count() == 0) {
// skip empty nodes: prevents legacy empty tags from being treated as invalid content items
// (migration will drop these anyways)
continue;
}
$node_count++;
// Array items are identified by a UUID, read from attribute or create a new one
if (isset($conf_section->attributes()->uuid)) {
$tagUUID = $conf_section->attributes()['uuid']->__toString();
@ -256,7 +263,8 @@ abstract class BaseModel
}
$fieldObject->addChildNode($tagUUID, $child_node);
}
} else {
}
if ($node_count == 0) {
// There's no content in config.xml for this array node.
$tagUUID = $internal_data->generateUUID();
$child_node = $fieldObject->newContainerField(