Merge pull request #13662 from appwrite/codex/fix-8042-handle-initials

Fix blank initials avatars for username handles
This commit is contained in:
Harsh Mahajan authored and GitHub committed 2026-09-15 12:01:32 +05:30
commit ac9c382fd8
3 files changed
+27 -2

No files matched your search

@@ -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;
@@ -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', [
@@ -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')]