lint/fixes, add group patch validation

This commit is contained in:
spiral 2021-09-22 13:48:34 -04:00
parent bc2c198a82
commit c472a7f6df
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
6 changed files with 20 additions and 12 deletions

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

View File

@ -35,12 +35,20 @@ namespace PluralKit.Core
public new void AssertIsValid()
{
if (Icon.Value != null && !MiscUtils.TryMatchUri(Icon.Value, out var avatarUri))
throw new ValidationError("icon");
if (BannerImage.Value != null && !MiscUtils.TryMatchUri(BannerImage.Value, out var bannerImage))
throw new ValidationError("banner");
if (Color.Value != null && (!Regex.IsMatch(Color.Value, "^[0-9a-fA-F]{6}$")))
throw new ValidationError("color");
if (Name.IsPresent)
AssertValid(Name.Value, "name", Limits.MaxGroupNameLength);
if (DisplayName.Value != null)
AssertValid(DisplayName.Value, "display_name", Limits.MaxGroupNameLength);
if (Description.Value != null)
AssertValid(Description.Value, "description", Limits.MaxDescriptionLength);
if (Icon.Value != null)
AssertValid(Icon.Value, "icon", Limits.MaxUriLength,
s => MiscUtils.TryMatchUri(s, out var avatarUri));
if (BannerImage.Value != null)
AssertValid(BannerImage.Value, "banner", Limits.MaxUriLength,
s => MiscUtils.TryMatchUri(s, out var bannerUri));
if (Color.Value != null)
AssertValid(Color.Value, "color", "^[0-9a-fA-F]{6}$");
}
#nullable disable

View File

@ -56,7 +56,7 @@ namespace PluralKit.Core
public new void AssertIsValid()
{
if (Name.IsPresent)
AssertValid(Name.Value, "display_name", Limits.MaxMemberNameLength);
AssertValid(Name.Value, "name", Limits.MaxMemberNameLength);
if (DisplayName.Value != null)
AssertValid(DisplayName.Value, "display_name", Limits.MaxMemberNameLength);
if (AvatarUrl.Value != null)