Skip to content

[Notifier] [Discord] Fix value limits #60269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class DiscordAuthorEmbedObject extends AbstractDiscordEmbedObject
*/
public function name(string $name): static
{
if (\strlen($name) > self::NAME_LIMIT) {
if (mb_strlen($name, 'UTF-8') > self::NAME_LIMIT) {
throw new LengthException(sprintf('Maximum length for the name is %d characters.', self::NAME_LIMIT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class DiscordEmbed extends AbstractDiscordEmbed
*/
public function title(string $title): static
{
if (\strlen($title) > self::TITLE_LIMIT) {
if (mb_strlen($title, 'UTF-8') > self::TITLE_LIMIT) {
throw new LengthException(sprintf('Maximum length for the title is %d characters.', self::TITLE_LIMIT));
}

Expand All @@ -41,7 +41,7 @@ public function title(string $title): static
*/
public function description(string $description): static
{
if (\strlen($description) > self::DESCRIPTION_LIMIT) {
if (mb_strlen($description, 'UTF-8') > self::DESCRIPTION_LIMIT) {
throw new LengthException(sprintf('Maximum length for the description is %d characters.', self::DESCRIPTION_LIMIT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class DiscordFieldEmbedObject extends AbstractDiscordEmbedObject
*/
public function name(string $name): static
{
if (\strlen($name) > self::NAME_LIMIT) {
if (mb_strlen($name, 'UTF-8') > self::NAME_LIMIT) {
throw new LengthException(sprintf('Maximum length for the name is %d characters.', self::NAME_LIMIT));
}

Expand All @@ -40,7 +40,7 @@ public function name(string $name): static
*/
public function value(string $value): static
{
if (\strlen($value) > self::VALUE_LIMIT) {
if (mb_strlen($value, 'UTF-8') > self::VALUE_LIMIT) {
throw new LengthException(sprintf('Maximum length for the value is %d characters.', self::VALUE_LIMIT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class DiscordFooterEmbedObject extends AbstractDiscordEmbedObject
*/
public function text(string $text): static
{
if (\strlen($text) > self::TEXT_LIMIT) {
if (mb_strlen($text, 'UTF-8') > self::TEXT_LIMIT) {
throw new LengthException(sprintf('Maximum length for the text is %d characters.', self::TEXT_LIMIT));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public function testThrowsWhenNameExceedsCharacterLimit()
$this->expectException(LengthException::class);
$this->expectExceptionMessage('Maximum length for the name is 256 characters.');

(new DiscordAuthorEmbedObject())->name(str_repeat('h', 257));
(new DiscordAuthorEmbedObject())->name(str_repeat('š', 257));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public function testThrowsWhenTitleExceedsCharacterLimit()
$this->expectException(LengthException::class);
$this->expectExceptionMessage('Maximum length for the title is 256 characters.');

(new DiscordEmbed())->title(str_repeat('h', 257));
(new DiscordEmbed())->title(str_repeat('š', 257));
}

public function testThrowsWhenDescriptionExceedsCharacterLimit()
{
$this->expectException(LengthException::class);
$this->expectExceptionMessage('Maximum length for the description is 4096 characters.');

(new DiscordEmbed())->description(str_repeat('h', 4097));
(new DiscordEmbed())->description(str_repeat('š', 4097));
}

public function testThrowsWhenFieldsLimitReached()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public function testThrowsWhenNameExceedsCharacterLimit()
$this->expectException(LengthException::class);
$this->expectExceptionMessage('Maximum length for the name is 256 characters.');

(new DiscordFieldEmbedObject())->name(str_repeat('h', 257));
(new DiscordFieldEmbedObject())->name(str_repeat('š', 257));
}

public function testThrowsWhenValueExceedsCharacterLimit()
{
$this->expectException(LengthException::class);
$this->expectExceptionMessage('Maximum length for the value is 1024 characters.');

(new DiscordFieldEmbedObject())->value(str_repeat('h', 1025));
(new DiscordFieldEmbedObject())->value(str_repeat('š', 1025));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public function testThrowsWhenTextExceedsCharacterLimit()
$this->expectException(LengthException::class);
$this->expectExceptionMessage('Maximum length for the text is 2048 characters.');

(new DiscordFooterEmbedObject())->text(str_repeat('h', 2049));
(new DiscordFooterEmbedObject())->text(str_repeat('š', 2049));
}
}