Skip to content

Commit

Permalink
[BUGFIX] Avoid accessing substructure when not of the expected type, r…
Browse files Browse the repository at this point in the history
…esolves #360
  • Loading branch information
fsuter committed Dec 27, 2024
1 parent e366421 commit 897aa5f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2024-12-27 Francois Suter (Idéative) <[email protected]>

* Add a delete reaction, resolves #361
* Avoid accessing substructure when not of the expected type, resolves #360

2024-11-24 Francois Suter (Idéative) <[email protected]>

Expand Down
10 changes: 6 additions & 4 deletions Classes/Handler/ArrayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ public function handleData($rawData, Importer $importer): array
)
);
$theValue = $event->getSubstructure();
$rows[$columnName] = $this->getSubstructureValues(
$theValue,
$columnData['substructureFields']
);
if (is_array($theValue)) {
$rows[$columnName] = $this->getSubstructureValues(
$theValue,
$columnData['substructureFields']
);
}
// Prepare for the case where no substructure was found
// If one was found, it is added later
$data[$referenceCounter][$columnName] = null;
Expand Down
15 changes: 10 additions & 5 deletions Classes/Handler/XmlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,16 @@ public function handleData($rawData, Importer $importer): array
)
);
$nodeList = $event->getSubstructure();
$rows[$columnName] = $this->getSubstructureValues(
$nodeList,
$columnData['substructureFields'],
$xPathObject
);
if ($nodeList instanceof \DOMNodeList) {
$rows[$columnName] = $this->getSubstructureValues(
$nodeList,
$columnData['substructureFields'],
$xPathObject
);
}
// Prepare for the case where no substructure was found
// If one was found, it is added later
$data[$referenceCounter][$columnName] = null;
} else {
$data[$referenceCounter][$columnName] = $this->getValue(
$theRecord,
Expand Down
11 changes: 11 additions & 0 deletions Tests/Unit/Handler/ArrayHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,17 @@ public function rawDataProvider(): array
],
],
],
'raw data with general array path but invalid value type' => [
'generalConfiguration' => [
'arrayPath' => 'data/items',
],
'rawData' => [
'data' => [
'items' => 'This should be an array',
],
],
'expectedStructure' => [],
],
'raw data with general invalid array path (empty)' => [
'generalConfiguration' => [
'arrayPath' => '',
Expand Down

0 comments on commit 897aa5f

Please sign in to comment.