misc: Remove URI check from EmbedBuilder (#1778)
`Uri.IsWellFormedUriString()` doesn't return the expected result for specific urls, removed until the DotNet team actually resolves it ( https://github.com/dotnet/runtime/issues/21626 )
This commit is contained in:
@@ -12,7 +12,6 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
private string _title;
|
private string _title;
|
||||||
private string _description;
|
private string _description;
|
||||||
private string _url;
|
|
||||||
private EmbedImage? _image;
|
private EmbedImage? _image;
|
||||||
private EmbedThumbnail? _thumbnail;
|
private EmbedThumbnail? _thumbnail;
|
||||||
private List<EmbedFieldBuilder> _fields;
|
private List<EmbedFieldBuilder> _fields;
|
||||||
@@ -70,26 +69,14 @@ namespace Discord
|
|||||||
/// <summary> Gets or sets the URL of an <see cref="Embed"/>. </summary>
|
/// <summary> Gets or sets the URL of an <see cref="Embed"/>. </summary>
|
||||||
/// <exception cref="ArgumentException" accessor="set">Url is not a well-formed <see cref="Uri"/>.</exception>
|
/// <exception cref="ArgumentException" accessor="set">Url is not a well-formed <see cref="Uri"/>.</exception>
|
||||||
/// <returns> The URL of the embed.</returns>
|
/// <returns> The URL of the embed.</returns>
|
||||||
public string Url
|
public string Url { get; set; }
|
||||||
{
|
|
||||||
get => _url;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(Url));
|
|
||||||
_url = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary> Gets or sets the thumbnail URL of an <see cref="Embed"/>. </summary>
|
/// <summary> Gets or sets the thumbnail URL of an <see cref="Embed"/>. </summary>
|
||||||
/// <exception cref="ArgumentException" accessor="set">Url is not a well-formed <see cref="Uri"/>.</exception>
|
/// <exception cref="ArgumentException" accessor="set">Url is not a well-formed <see cref="Uri"/>.</exception>
|
||||||
/// <returns> The thumbnail URL of the embed.</returns>
|
/// <returns> The thumbnail URL of the embed.</returns>
|
||||||
public string ThumbnailUrl
|
public string ThumbnailUrl
|
||||||
{
|
{
|
||||||
get => _thumbnail?.Url;
|
get => _thumbnail?.Url;
|
||||||
set
|
set => _thumbnail = new EmbedThumbnail(value, null, null, null);
|
||||||
{
|
|
||||||
if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(ThumbnailUrl));
|
|
||||||
_thumbnail = new EmbedThumbnail(value, null, null, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// <summary> Gets or sets the image URL of an <see cref="Embed"/>. </summary>
|
/// <summary> Gets or sets the image URL of an <see cref="Embed"/>. </summary>
|
||||||
/// <exception cref="ArgumentException" accessor="set">Url is not a well-formed <see cref="Uri"/>.</exception>
|
/// <exception cref="ArgumentException" accessor="set">Url is not a well-formed <see cref="Uri"/>.</exception>
|
||||||
@@ -97,11 +84,7 @@ namespace Discord
|
|||||||
public string ImageUrl
|
public string ImageUrl
|
||||||
{
|
{
|
||||||
get => _image?.Url;
|
get => _image?.Url;
|
||||||
set
|
set => _image = new EmbedImage(value, null, null, null);
|
||||||
{
|
|
||||||
if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(ImageUrl));
|
|
||||||
_image = new EmbedImage(value, null, null, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Gets or sets the list of <see cref="EmbedFieldBuilder"/> of an <see cref="Embed"/>. </summary>
|
/// <summary> Gets or sets the list of <see cref="EmbedFieldBuilder"/> of an <see cref="Embed"/>. </summary>
|
||||||
@@ -553,8 +536,6 @@ namespace Discord
|
|||||||
public class EmbedAuthorBuilder
|
public class EmbedAuthorBuilder
|
||||||
{
|
{
|
||||||
private string _name;
|
private string _name;
|
||||||
private string _url;
|
|
||||||
private string _iconUrl;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the maximum author name length allowed by Discord.
|
/// Gets the maximum author name length allowed by Discord.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -585,15 +566,7 @@ namespace Discord
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The URL of the author field.
|
/// The URL of the author field.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public string Url
|
public string Url { get; set; }
|
||||||
{
|
|
||||||
get => _url;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(Url));
|
|
||||||
_url = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the icon URL of the author field.
|
/// Gets or sets the icon URL of the author field.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -601,15 +574,7 @@ namespace Discord
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The icon URL of the author field.
|
/// The icon URL of the author field.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public string IconUrl
|
public string IconUrl { get; set; }
|
||||||
{
|
|
||||||
get => _iconUrl;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(IconUrl));
|
|
||||||
_iconUrl = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the name of the author field.
|
/// Sets the name of the author field.
|
||||||
@@ -671,7 +636,6 @@ namespace Discord
|
|||||||
public class EmbedFooterBuilder
|
public class EmbedFooterBuilder
|
||||||
{
|
{
|
||||||
private string _text;
|
private string _text;
|
||||||
private string _iconUrl;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the maximum footer length allowed by Discord.
|
/// Gets the maximum footer length allowed by Discord.
|
||||||
@@ -703,15 +667,7 @@ namespace Discord
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The icon URL of the footer field.
|
/// The icon URL of the footer field.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public string IconUrl
|
public string IconUrl { get; set; }
|
||||||
{
|
|
||||||
get => _iconUrl;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI.", paramName: nameof(IconUrl));
|
|
||||||
_iconUrl = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the name of the footer field.
|
/// Sets the name of the footer field.
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Discord
|
|
||||||
{
|
|
||||||
internal static class StringExtensions
|
|
||||||
{
|
|
||||||
public static bool IsNullOrUri(this string url) =>
|
|
||||||
string.IsNullOrEmpty(url) || Uri.IsWellFormedUriString(url, UriKind.Absolute);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -190,42 +190,6 @@ namespace Discord
|
|||||||
Assert.Equal(result.ThumbnailUrl, url);
|
Assert.Equal(result.ThumbnailUrl, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Tests that invalid urls throw an <see cref="ArgumentException"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="url">The url to set.</param>
|
|
||||||
[Theory]
|
|
||||||
[InlineData(" ")]
|
|
||||||
[InlineData("not a url")]
|
|
||||||
public void Url_Invalid(string url)
|
|
||||||
{
|
|
||||||
Assert.Throws<ArgumentException>(()
|
|
||||||
=> new EmbedBuilder()
|
|
||||||
.WithUrl(url));
|
|
||||||
Assert.Throws<ArgumentException>(()
|
|
||||||
=> new EmbedBuilder()
|
|
||||||
.WithImageUrl(url));
|
|
||||||
Assert.Throws<ArgumentException>(()
|
|
||||||
=> new EmbedBuilder()
|
|
||||||
.WithThumbnailUrl(url));
|
|
||||||
|
|
||||||
Assert.Throws<ArgumentException>(() =>
|
|
||||||
{
|
|
||||||
var b = new EmbedBuilder();
|
|
||||||
b.Url = url;
|
|
||||||
});
|
|
||||||
Assert.Throws<ArgumentException>(() =>
|
|
||||||
{
|
|
||||||
var b = new EmbedBuilder();
|
|
||||||
b.ImageUrl = url;
|
|
||||||
});
|
|
||||||
Assert.Throws<ArgumentException>(() =>
|
|
||||||
{
|
|
||||||
var b = new EmbedBuilder();
|
|
||||||
b.ThumbnailUrl = url;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests the value of the <see cref="EmbedBuilder.Length"/> property when there are no fields set.
|
/// Tests the value of the <see cref="EmbedBuilder.Length"/> property when there are no fields set.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -343,24 +307,6 @@ namespace Discord
|
|||||||
Assert.Equal(name, footer.Text);
|
Assert.Equal(name, footer.Text);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests that invalid URLs throw an <see cref="ArgumentException"/>.
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
public void EmbedFooterBuilder_InvalidURL()
|
|
||||||
{
|
|
||||||
IEnumerable<string> InvalidUrls()
|
|
||||||
{
|
|
||||||
yield return "not a url";
|
|
||||||
}
|
|
||||||
foreach (var url in InvalidUrls())
|
|
||||||
{
|
|
||||||
Assert.Throws<ArgumentException>(() =>
|
|
||||||
{
|
|
||||||
new EmbedFooterBuilder().WithIconUrl(url);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Tests that invalid text throws an <see cref="ArgumentException"/>.
|
/// Tests that invalid text throws an <see cref="ArgumentException"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user