[backend/core] Ignore poll options consisting only of whitespace

This fixes compatibility with certain mastodon clients that send an extra empty-string poll option.
This commit is contained in:
Laura Hausmann 2024-06-14 20:04:38 +02:00
parent ed38dc3788
commit a703b63876
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -79,11 +79,13 @@ public class NoteService(
throw GracefulException.UnprocessableEntity("Cannot renote or quote a pure renote"); throw GracefulException.UnprocessableEntity("Cannot renote or quote a pure renote");
if (reply?.IsPureRenote ?? false) if (reply?.IsPureRenote ?? false)
throw GracefulException.UnprocessableEntity("Cannot reply to a pure renote"); throw GracefulException.UnprocessableEntity("Cannot reply to a pure renote");
if (poll is { Choices.Count: < 2 })
throw GracefulException.UnprocessableEntity("Polls must have at least two options");
if (user.IsSuspended) if (user.IsSuspended)
throw GracefulException.Forbidden("User is suspended"); throw GracefulException.Forbidden("User is suspended");
poll?.Choices.RemoveAll(string.IsNullOrWhiteSpace);
if (poll is { Choices.Count: < 2 })
throw GracefulException.UnprocessableEntity("Polls must have at least two options");
if (renote != null) if (renote != null)
{ {
var pureRenote = text == null && poll == null && attachments is not { Count: > 0 }; var pureRenote = text == null && poll == null && attachments is not { Count: > 0 };
@ -495,6 +497,10 @@ public class NoteService(
if (poll != null) if (poll != null)
{ {
poll.Choices.RemoveAll(string.IsNullOrWhiteSpace);
if (poll.Choices.Count < 2)
throw GracefulException.UnprocessableEntity("Polls must have at least two options");
if (note.Poll != null) if (note.Poll != null)
{ {
if (note.Poll.ExpiresAt != poll.ExpiresAt) if (note.Poll.ExpiresAt != poll.ExpiresAt)