Skip to content

Commit 2eb539d

Browse files
committed
system: use is_int()/array_key_first() in toArray() and fromArray() #9485
The approximation of the magic here is that we are looking for array elements created by a natural append [] = or equivalent which has an integer key of a rough range of 0 to count() - 1, but not always as we can see from the ticket. unset() breaks the pledge of sequential lists and makes array_is_list() fail. Sorting would also break the sequential pledge without resetting the keyes using array_values() but that approach is too broad. Instead, get a single key we can do a strict int type check on so that we are as likely to succeed as was the case before the change in 7ee3b2c. It's also fast. ;)
1 parent 9e80580 commit 2eb539d

File tree

1 file changed

+3
-3
lines changed
  • src/opnsense/mvc/app/library/OPNsense/Core

1 file changed

+3
-3
lines changed

src/opnsense/mvc/app/library/OPNsense/Core/Config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function toArray($forceList = null, $node = null)
118118
$old_content = $result[$xmlNodeName];
119119
// check if array content is associative, move items to new list
120120
// (handles first item of specific type)
121-
if (!is_array($old_content) || !array_is_list($old_content)) {
121+
if (!is_array($old_content) || !is_int(array_key_first($old_content))) {
122122
$result[$xmlNodeName] = array();
123123
$result[$xmlNodeName][] = $old_content;
124124
}
@@ -240,10 +240,10 @@ function ($errno, $errstr, $errfile, $errline) {
240240
}
241241
}
242242
continue;
243-
} elseif (is_numeric($itemKey)) {
243+
} elseif (is_int($itemKey)) {
244244
// recurring tag (content), use parent tagname.
245245
$childNode = $node->addChild($parentTagName);
246-
} elseif (is_array($itemValue) && array_is_list($itemValue)) {
246+
} elseif (is_array($itemValue) && is_int(array_key_first($itemValue))) {
247247
// recurring tag, skip placeholder.
248248
$childNode = $node;
249249
} else {

0 commit comments

Comments
 (0)