From c08c089341051df93c50d358e63d04d324fe1f5d Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Mon, 14 Sep 2026 15:33:56 +0530 Subject: [PATCH 1/7] fix(avatars): render initials for username handles --- app/init/constants.php | 2 +- .../AvatarPhotos/Providers/Initials.php | 2 ++ tests/e2e/Services/Avatars/AvatarsBase.php | 23 +++++++++++++++++++ .../AvatarPhotos/Providers/InitialsTest.php | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/init/constants.php b/app/init/constants.php index bbb8f549db..ee06d47db3 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -99,7 +99,7 @@ const APP_PROJECT_ACCESS = 24 * 60 * 60; // 24 hours const APP_RESOURCE_TOKEN_ACCESS = 24 * 60 * 60; // 24 hours const APP_FILE_ACCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours -const APP_CACHE_BUSTER = 4327; +const APP_CACHE_BUSTER = 4328; const APP_VERSION_STABLE = '2.1.0'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; diff --git a/src/Appwrite/AvatarPhotos/Providers/Initials.php b/src/Appwrite/AvatarPhotos/Providers/Initials.php index 29ae83014e..126781987c 100644 --- a/src/Appwrite/AvatarPhotos/Providers/Initials.php +++ b/src/Appwrite/AvatarPhotos/Providers/Initials.php @@ -106,6 +106,8 @@ class Initials extends Photo */ private function getWords(string $name): array { + // A leading @ identifies a handle; the following name supplies its initials. + $name = \preg_replace('/^@(?=[\p{L}\p{N}])/u', '', \trim($name)) ?? $name; $words = \explode(' ', \trim($name)); // Fallback: split on underscores when there is no space diff --git a/tests/e2e/Services/Avatars/AvatarsBase.php b/tests/e2e/Services/Avatars/AvatarsBase.php index e563b9d314..de9258b009 100644 --- a/tests/e2e/Services/Avatars/AvatarsBase.php +++ b/tests/e2e/Services/Avatars/AvatarsBase.php @@ -537,6 +537,29 @@ trait AvatarsBase $this->assertEquals(400, $response['headers']['status-code']); } + public function testHandleInitials(): void + { + $signatures = []; + foreach (['@ItzNotABug', 'ItzNotABug'] as $name) { + $response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [ + 'x-appwrite-project' => $this->getProject()['$id'], + ], [ + 'name' => $name, + 'width' => 100, + 'height' => 100, + ]); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('image/png', $response['headers']['content-type']); + + $image = new \Imagick(); + $image->readImageBlob($response['body']); + $this->assertGreaterThan(1, $image->getImageColors()); + $signatures[] = $image->getImageSignature(); + } + + $this->assertSame($signatures[0], $signatures[1]); + } + public function testInitialImage() { $response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [ diff --git a/tests/unit/AvatarPhotos/Providers/InitialsTest.php b/tests/unit/AvatarPhotos/Providers/InitialsTest.php index a6e9b6aa17..762f8b1304 100644 --- a/tests/unit/AvatarPhotos/Providers/InitialsTest.php +++ b/tests/unit/AvatarPhotos/Providers/InitialsTest.php @@ -109,6 +109,10 @@ final class InitialsTest extends TestCase yield 'words starting with neither letter nor digit' => ['W (Hello) W', 'W W']; yield 'underscores stand in for spaces' => ['walter_white', 'Walter White']; yield 'padding and repeated spaces' => [' Walter White ', 'Walter White']; + yield 'username handle' => ['@ItzNotABug', 'ItzNotABug']; + yield 'padded handle with underscores' => [' @walter_white ', 'Walter White']; + yield 'unicode handle' => ['@élise', 'Élise']; + yield 'numeric handle' => ['@0', '0']; } #[DataProvider('provideEquivalentNames')] From e3d0f03f8df336ddf7a444e7a577b31c8044dea9 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 15 Sep 2026 11:40:36 +0530 Subject: [PATCH 2/7] fix(avatars): strip handle prefix with ltrim instead of a regex --- src/Appwrite/AvatarPhotos/Providers/Initials.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/AvatarPhotos/Providers/Initials.php b/src/Appwrite/AvatarPhotos/Providers/Initials.php index 126781987c..042a1241c8 100644 --- a/src/Appwrite/AvatarPhotos/Providers/Initials.php +++ b/src/Appwrite/AvatarPhotos/Providers/Initials.php @@ -106,9 +106,8 @@ class Initials extends Photo */ private function getWords(string $name): array { - // A leading @ identifies a handle; the following name supplies its initials. - $name = \preg_replace('/^@(?=[\p{L}\p{N}])/u', '', \trim($name)) ?? $name; - $words = \explode(' ', \trim($name)); + // Handles like @walter take their initials from the name after the @ + $words = \explode(' ', \ltrim(\trim($name), '@')); // Fallback: split on underscores when there is no space $words = (\count($words) === 1) ? \explode('_', $words[0]) : $words; From ce8965ba86e6f48c9cb8507a0def76c733c2a98d Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 15 Sep 2026 11:40:36 +0530 Subject: [PATCH 3/7] chore: keep APP_CACHE_BUSTER at 4327 /v1/avatars/initials has no cache label, so the salt never reached it; bumping it only orphaned file preview and avatar cache entries. --- app/init/constants.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/init/constants.php b/app/init/constants.php index ee06d47db3..bbb8f549db 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -99,7 +99,7 @@ const APP_PROJECT_ACCESS = 24 * 60 * 60; // 24 hours const APP_RESOURCE_TOKEN_ACCESS = 24 * 60 * 60; // 24 hours const APP_FILE_ACCESS = 24 * 60 * 60; // 24 hours const APP_CACHE_UPDATE = 24 * 60 * 60; // 24 hours -const APP_CACHE_BUSTER = 4328; +const APP_CACHE_BUSTER = 4327; const APP_VERSION_STABLE = '2.1.0'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; From f5aaba11df23fa05c8e3aa08cffab8acb0c56b1c Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 15 Sep 2026 11:41:58 +0530 Subject: [PATCH 4/7] docs(avatars): note handle prefix in getWords docblock --- src/Appwrite/AvatarPhotos/Providers/Initials.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/AvatarPhotos/Providers/Initials.php b/src/Appwrite/AvatarPhotos/Providers/Initials.php index 042a1241c8..4442c3ae93 100644 --- a/src/Appwrite/AvatarPhotos/Providers/Initials.php +++ b/src/Appwrite/AvatarPhotos/Providers/Initials.php @@ -100,13 +100,13 @@ class Initials extends Photo /** * Words that start with a letter or digit, split on spaces — or on - * underscores when the label has none. + * underscores when the label has none. A leading @, as in a handle, is + * ignored. * * @return string[] */ private function getWords(string $name): array { - // Handles like @walter take their initials from the name after the @ $words = \explode(' ', \ltrim(\trim($name), '@')); // Fallback: split on underscores when there is no space From 26f7c1bc7679c3ad980954ea9f178bc9d7d678e0 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 15 Sep 2026 11:41:58 +0530 Subject: [PATCH 5/7] test(avatars): narrow handle initials coverage to the handle claim --- tests/e2e/Services/Avatars/AvatarsBase.php | 29 +++++++------------ .../AvatarPhotos/Providers/InitialsTest.php | 2 -- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/tests/e2e/Services/Avatars/AvatarsBase.php b/tests/e2e/Services/Avatars/AvatarsBase.php index de9258b009..5c06f41718 100644 --- a/tests/e2e/Services/Avatars/AvatarsBase.php +++ b/tests/e2e/Services/Avatars/AvatarsBase.php @@ -537,27 +537,20 @@ trait AvatarsBase $this->assertEquals(400, $response['headers']['status-code']); } - public function testHandleInitials(): void + public function testGetInitialsHandle(): void { - $signatures = []; - foreach (['@ItzNotABug', 'ItzNotABug'] as $name) { - $response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [ - 'x-appwrite-project' => $this->getProject()['$id'], - ], [ - 'name' => $name, - 'width' => 100, - 'height' => 100, - ]); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png', $response['headers']['content-type']); + $response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [ + 'x-appwrite-project' => $this->getProject()['$id'], + ], [ + 'name' => '@ItzNotABug', + 'width' => 100, + 'height' => 100, + ]); - $image = new \Imagick(); - $image->readImageBlob($response['body']); - $this->assertGreaterThan(1, $image->getImageColors()); - $signatures[] = $image->getImageSignature(); - } + $image = new \Imagick(); + $image->readImageBlob($response['body']); - $this->assertSame($signatures[0], $signatures[1]); + $this->assertGreaterThan(1, $image->getImageColors(), 'A handle rendered a blank square.'); } public function testInitialImage() diff --git a/tests/unit/AvatarPhotos/Providers/InitialsTest.php b/tests/unit/AvatarPhotos/Providers/InitialsTest.php index 762f8b1304..c755d8dfba 100644 --- a/tests/unit/AvatarPhotos/Providers/InitialsTest.php +++ b/tests/unit/AvatarPhotos/Providers/InitialsTest.php @@ -111,8 +111,6 @@ final class InitialsTest extends TestCase yield 'padding and repeated spaces' => [' Walter White ', 'Walter White']; yield 'username handle' => ['@ItzNotABug', 'ItzNotABug']; yield 'padded handle with underscores' => [' @walter_white ', 'Walter White']; - yield 'unicode handle' => ['@élise', 'Élise']; - yield 'numeric handle' => ['@0', '0']; } #[DataProvider('provideEquivalentNames')] From 30c620c7ba17fe5a294e0aabca7742f6f3fd2345 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 15 Sep 2026 11:42:56 +0530 Subject: [PATCH 6/7] test(avatars): keep numeric handle equivalence case --- tests/unit/AvatarPhotos/Providers/InitialsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/AvatarPhotos/Providers/InitialsTest.php b/tests/unit/AvatarPhotos/Providers/InitialsTest.php index c755d8dfba..6bc917bf5a 100644 --- a/tests/unit/AvatarPhotos/Providers/InitialsTest.php +++ b/tests/unit/AvatarPhotos/Providers/InitialsTest.php @@ -111,6 +111,7 @@ final class InitialsTest extends TestCase yield 'padding and repeated spaces' => [' Walter White ', 'Walter White']; yield 'username handle' => ['@ItzNotABug', 'ItzNotABug']; yield 'padded handle with underscores' => [' @walter_white ', 'Walter White']; + yield 'numeric handle' => ['@0', '0']; } #[DataProvider('provideEquivalentNames')] From 9b149ec349a513433cb474824f5b32ee6c9ee399 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 15 Sep 2026 11:46:37 +0530 Subject: [PATCH 7/7] test(avatars): compare handle initials with the plain name over the API --- tests/e2e/Services/Avatars/AvatarsBase.php | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tests/e2e/Services/Avatars/AvatarsBase.php b/tests/e2e/Services/Avatars/AvatarsBase.php index 5c06f41718..cd95aa90b2 100644 --- a/tests/e2e/Services/Avatars/AvatarsBase.php +++ b/tests/e2e/Services/Avatars/AvatarsBase.php @@ -539,18 +539,23 @@ trait AvatarsBase public function testGetInitialsHandle(): void { - $response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [ - 'x-appwrite-project' => $this->getProject()['$id'], - ], [ - 'name' => '@ItzNotABug', - 'width' => 100, - 'height' => 100, - ]); + $signatures = []; - $image = new \Imagick(); - $image->readImageBlob($response['body']); + foreach (['@ItzNotABug', 'ItzNotABug'] as $name) { + $response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [ + 'x-appwrite-project' => $this->getProject()['$id'], + ], [ + 'name' => $name, + 'width' => 100, + 'height' => 100, + ]); - $this->assertGreaterThan(1, $image->getImageColors(), 'A handle rendered a blank square.'); + $image = new \Imagick(); + $image->readImageBlob($response['body']); + $signatures[] = $image->getImageSignature(); + } + + $this->assertSame($signatures[1], $signatures[0], 'A handle rendered differently from its name.'); } public function testInitialImage()