diff --git a/src/Traits/HashIdTrait.php b/src/Traits/HashIdTrait.php index a2a720e6..fa87bb35 100644 --- a/src/Traits/HashIdTrait.php +++ b/src/Traits/HashIdTrait.php @@ -143,6 +143,11 @@ private function locateAndDecodeIds($requestData, $key): mixed */ private function processField($data, $keysTodo, $currentFieldName): mixed { + // is the current field a null?! we can give it back and chill out + if(is_null($data)) { + return $data; + } + // check if there are no more fields to be processed if (empty($keysTodo)) { // there are no more keys left - so basically we need to decode this entry diff --git a/tests/Unit/Traits/HashIdTraitTest.php b/tests/Unit/Traits/HashIdTraitTest.php new file mode 100644 index 00000000..0f2192d4 --- /dev/null +++ b/tests/Unit/Traits/HashIdTraitTest.php @@ -0,0 +1,36 @@ +trait = new class { + use HashIdTrait; + }; + } + + public function testProcessFieldShouldNotWrapANullInAnArray(): void + { + $data = null; + $keysTodo = ['*']; + $currentFieldName = null; + $reflection = new ReflectionClass($this->trait); + $method = $reflection->getMethod('processField'); + + $result = $method->invoke($this->trait, $data, $keysTodo, $currentFieldName); + + $this->assertNull($result); + } +}