diff --git a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs index 5b92e02a5..0304120f5 100644 --- a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs +++ b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs @@ -408,22 +408,22 @@ namespace Discord if (Length > MaxEmbedLength) throw new InvalidOperationException($"Total embed length must be less than or equal to {MaxEmbedLength}."); if (!string.IsNullOrEmpty(Url)) - UrlValidation.Validate(Url); + UrlValidation.Validate(Url, true); if (!string.IsNullOrEmpty(ThumbnailUrl)) - UrlValidation.Validate(ThumbnailUrl); - if (!string.IsNullOrEmpty(ImageUrl) && !ImageUrl.StartsWith("attachment://", StringComparison.Ordinal)) - UrlValidation.Validate(ImageUrl); + UrlValidation.Validate(ThumbnailUrl, true); + if (!string.IsNullOrEmpty(ImageUrl)) + UrlValidation.Validate(ImageUrl, true); if (Author != null) { if (!string.IsNullOrEmpty(Author.Url)) - UrlValidation.Validate(Author.Url); + UrlValidation.Validate(Author.Url, true); if (!string.IsNullOrEmpty(Author.IconUrl)) - UrlValidation.Validate(Author.IconUrl); + UrlValidation.Validate(Author.IconUrl, true); } if(Footer != null) { if (!string.IsNullOrEmpty(Footer.IconUrl)) - UrlValidation.Validate(Footer.IconUrl); + UrlValidation.Validate(Footer.IconUrl, true); } var fields = ImmutableArray.CreateBuilder(Fields.Count); for (int i = 0; i < Fields.Count; i++) diff --git a/src/Discord.Net.Core/Utils/UrlValidation.cs b/src/Discord.Net.Core/Utils/UrlValidation.cs index ab651da0d..2699bdc9f 100644 --- a/src/Discord.Net.Core/Utils/UrlValidation.cs +++ b/src/Discord.Net.Core/Utils/UrlValidation.cs @@ -9,14 +9,15 @@ namespace Discord.Utils /// should be used for url buttons. /// /// The URL to validate before sending to Discord. + /// to allow the attachment:// protocol; otherwise . /// A URL must include a protocol (http or https). /// true if URL is valid by our standard, false if null, throws an error upon invalid. - public static bool Validate(string url) + public static bool Validate(string url, bool allowAttachments = false) { if (string.IsNullOrEmpty(url)) return false; - if (!(url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))) - throw new InvalidOperationException($"The url {url} must include a protocol (either HTTP or HTTPS)"); + if (!(url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || url.StartsWith("https://", StringComparison.OrdinalIgnoreCase) || allowAttachments ? url.StartsWith("attachment://", StringComparison.Ordinal) : false)) + throw new InvalidOperationException($"The url {url} must include a protocol (either {(allowAttachments ? "HTTP, HTTPS, or ATTACHMENT" : "HTTP or HTTPS")})"); return true; }