From bbe0f3afe45c0ed3bb10f891e5d5c111ec62d8df Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Thu, 14 Jan 2021 11:29:37 +0100 Subject: [PATCH] MVC model parsing: it seems that https://github.com/opnsense/core/commit/1e092de4956f1c594ee7175a87d9d7a82b5dcc3c 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 --- .../mvc/app/models/OPNsense/Base/BaseModel.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php b/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php index 025c86a7a..248a1c732 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php @@ -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(