Skip to content

Commit

Permalink
Fix a bug in EmbedBuilder.Length when there is an EmbedField with no …
Browse files Browse the repository at this point in the history
…Value (#2345)

* Update EmbedBuilder.cs

Fixes a bug where 'EmbedBuilder.Length' will throw an exception of type 'System.NullReferenceException' when a field doesn't have a value.

* Update EmbedBuilder.cs

Fixed an incorrect assuption that `Value` was a `string?`

* Update EmbedBuilder.cs

Fixed one more null check

* Update EmbedBuilder.cs

Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com>
  • Loading branch information
Hampo and quinchs committed Sep 4, 2022
1 parent 11ece4b commit 2b86a79
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public int Length
int authorLength = Author?.Name?.Length ?? 0;
int descriptionLength = Description?.Length ?? 0;
int footerLength = Footer?.Text?.Length ?? 0;
int fieldSum = Fields.Sum(f => f.Name.Length + f.Value.ToString().Length);
int fieldSum = Fields.Sum(f => f.Name.Length + (f.Value?.ToString()?.Length ?? 0));

return titleLength + authorLength + descriptionLength + footerLength + fieldSum;
}
Expand Down

0 comments on commit 2b86a79

Please sign in to comment.