spatie / laravel-backup

A package to backup your Laravel app
https://spatie.be/docs/laravel-backup
MIT License
5.61k stars 758 forks source link

[9.x] Fix empty string in `backup.notifications.discord.username` to fail sending a notification #1821

Closed RVxLab closed 1 month ago

RVxLab commented 2 months ago

Fixes #1815

This PR fixes an issue caused by using an empty string for the Discord Webhook username property.

According to Discord's documentation, the username field is optional and when set, requires it to be between 1 and 80 characters long. This lines up with the name field when creating a webhook.

The current implementation of the notification doesn't follow that. If the backup.notifications.discord.username is an empty string (which is currently the default), the notification is never sent due to a validation error. See the mentioned issue above for details.

This PR fixes these issues by only setting the username set in the config if it's not empty.

To test this, I created a server and added a webhook with the name Test McWebhook:

image

I applied the fix to a project locally and ran it with 3 usernames in order:

image

As a final change, I removed the ?? 'Laravel Backup' expression when setting the username. Since $username is non-nullable, that expression is never run.

freekmurze commented 1 month ago

Thanks!