[Fix] Prevent multiline values in short TextInputs (#2789)
* 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>
This commit is contained in:
@@ -1406,6 +1406,9 @@ namespace Discord
|
|||||||
/// <exception cref="ArgumentOutOfRangeException">
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
/// <see cref="Value"/>.Length is greater than <see cref="LargestMaxLength"/> or <see cref="MaxLength"/>.
|
/// <see cref="Value"/>.Length is greater than <see cref="LargestMaxLength"/> or <see cref="MaxLength"/>.
|
||||||
/// </exception>
|
/// </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
|
public string Value
|
||||||
{
|
{
|
||||||
get => _value;
|
get => _value;
|
||||||
@@ -1415,6 +1418,7 @@ namespace Discord
|
|||||||
throw new ArgumentOutOfRangeException(nameof(value), $"Value must not be longer than {MaxLength ?? LargestMaxLength}.");
|
throw new ArgumentOutOfRangeException(nameof(value), $"Value must not be longer than {MaxLength ?? LargestMaxLength}.");
|
||||||
if (value?.Length < (MinLength ?? 0))
|
if (value?.Length < (MinLength ?? 0))
|
||||||
throw new ArgumentOutOfRangeException(nameof(value), $"Value must not be shorter than {MinLength}");
|
throw new ArgumentOutOfRangeException(nameof(value), $"Value must not be shorter than {MinLength}");
|
||||||
|
|
||||||
_value = value;
|
_value = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1550,6 +1554,9 @@ namespace Discord
|
|||||||
throw new ArgumentException("TextInputComponents must have a custom id.", nameof(CustomId));
|
throw new ArgumentException("TextInputComponents must have a custom id.", nameof(CustomId));
|
||||||
if (string.IsNullOrWhiteSpace(Label))
|
if (string.IsNullOrWhiteSpace(Label))
|
||||||
throw new ArgumentException("TextInputComponents must have a label.", nameof(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);
|
return new TextInputComponent(CustomId, Label, Placeholder, MinLength, MaxLength, Style, Required, Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user