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.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;

View File

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

View File

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