From 418889593c0c26e224b7cf3faa1b8624f0ddd5fa Mon Sep 17 00:00:00 2001 From: Arie Timmerman Date: Thu, 9 Oct 2025 20:11:36 +0000 Subject: [PATCH] Fixes Parsing errors when `name` is an empty object Fixes #138 --- src/Attribute/Complex.php | 5 +++++ tests/BasicTest.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/Attribute/Complex.php b/src/Attribute/Complex.php index f09e989..f83dff5 100644 --- a/src/Attribute/Complex.php +++ b/src/Attribute/Complex.php @@ -215,6 +215,11 @@ public function replace($value, Model &$object, Path $path = null, $removeIfNotS return; } + // if value is empty, nothing to do + if (empty($value)) { + return; + } + // if there is no path, keys of value are attribute paths foreach ($value as $key => $v) { if (is_numeric($key)) { diff --git a/tests/BasicTest.php b/tests/BasicTest.php index 267094c..5d2ae17 100644 --- a/tests/BasicTest.php +++ b/tests/BasicTest.php @@ -524,4 +524,37 @@ public function testTotalResultsOnly(){ $response = $this->get('/scim/v2/Users?count=0'); $this->assertTrue(true); } + + public function testPostTopLevelEmptyName() + { + $response = $this->post('/scim/v2/Users', [ + // "id" => 1, + "schemas" => [ + "urn:ietf:params:scim:schemas:core:2.0:User", + ], + "name" => [], + "userName" => "Dr. Marie Jo", + "password" => "Password123", + "emails" => [ + [ + "value" => "mariejo@example.com", + "type" => "primary", + "primary" => true + ] + ] + + ]); + + $this->assertEquals( + 201, + $response->baseResponse->getStatusCode(), + 'Wrong status: ' . $response->baseResponse->content() + ); + + $json = $response->json(); + + $this->assertArrayHasKey('urn:ietf:params:scim:schemas:core:2.0:User', $json); + $this->assertEquals('mariejo@example.com', $json['urn:ietf:params:scim:schemas:core:2.0:User']['emails'][0]['value']); + $this->assertEquals('Dr. Marie Jo', $json['urn:ietf:params:scim:schemas:core:2.0:User']['userName']); + } }