Skip to content

Commit

Permalink
[Fix] Prevent multiline values in short TextInputs (#2789)
Browse files Browse the repository at this point in the history
* Prevent multiline values in short Textinputs

* Change exception

* Move check to build method

* Update src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs

---------

Co-authored-by: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com>
  • Loading branch information
BattleRush and Misha-133 committed Oct 17, 2023
1 parent 7b5c40a commit 33e8340
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,9 @@ public int? MaxLength
/// <exception cref="ArgumentOutOfRangeException">
/// <see cref="Value"/>.Length is greater than <see cref="LargestMaxLength"/> or <see cref="MaxLength"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// <see cref="Style"/> is <see cref="TextInputStyle.Short"/> and <see cref="Value"/> contains a new line character.
/// </exception>
public string Value
{
get => _value;
Expand All @@ -1415,6 +1418,7 @@ public string Value
throw new ArgumentOutOfRangeException(nameof(value), $"Value must not be longer than {MaxLength ?? LargestMaxLength}.");
if (value?.Length < (MinLength ?? 0))
throw new ArgumentOutOfRangeException(nameof(value), $"Value must not be shorter than {MinLength}");

_value = value;
}
}
Expand Down Expand Up @@ -1550,6 +1554,9 @@ public TextInputComponent Build()
throw new ArgumentException("TextInputComponents must have a custom id.", nameof(CustomId));
if (string.IsNullOrWhiteSpace(Label))
throw new ArgumentException("TextInputComponents must have a label.", nameof(Label));
if (Style == TextInputStyle.Short && Value?.Contains('\n') == true)
throw new ArgumentException($"Value must not contain new line characters when style is {TextInputStyle.Short}.", nameof(Value));

return new TextInputComponent(CustomId, Label, Placeholder, MinLength, MaxLength, Style, Required, Value);
}
}
Expand Down

0 comments on commit 33e8340

Please sign in to comment.