[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:
parent
ed38dc3788
commit
a703b63876
1 changed files with 8 additions and 2 deletions
|
@ -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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue