diff --git a/src/Appwrite/AvatarPhotos/Providers/Initials.php b/src/Appwrite/AvatarPhotos/Providers/Initials.php index 29ae83014e..4442c3ae93 100644 --- a/src/Appwrite/AvatarPhotos/Providers/Initials.php +++ b/src/Appwrite/AvatarPhotos/Providers/Initials.php @@ -100,13 +100,14 @@ 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 { - $words = \explode(' ', \trim($name)); + $words = \explode(' ', \ltrim(\trim($name), '@')); // Fallback: split on underscores when there is no space $words = (\count($words) === 1) ? \explode('_', $words[0]) : $words; diff --git a/tests/e2e/Services/Avatars/AvatarsBase.php b/tests/e2e/Services/Avatars/AvatarsBase.php index e563b9d314..cd95aa90b2 100644 --- a/tests/e2e/Services/Avatars/AvatarsBase.php +++ b/tests/e2e/Services/Avatars/AvatarsBase.php @@ -537,6 +537,27 @@ trait AvatarsBase $this->assertEquals(400, $response['headers']['status-code']); } + 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, + ]); + + $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() { $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..6bc917bf5a 100644 --- a/tests/unit/AvatarPhotos/Providers/InitialsTest.php +++ b/tests/unit/AvatarPhotos/Providers/InitialsTest.php @@ -109,6 +109,9 @@ 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 'numeric handle' => ['@0', '0']; } #[DataProvider('provideEquivalentNames')]