[9.x] Fix empty string in backup.notifications.discord.username
to fail sending a notification
#1821
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thename
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:
I applied the fix to a project locally and ran it with 3 usernames in order:
'Laravel Backup'
''
'Some Other Custom Name'
As a final change, I removed the
?? 'Laravel Backup'
expression when setting the username. Since$username
is non-nullable, that expression is never run.