From 55f77df39ecd3ecf2cdae44ffe125c022e7f7bc7 Mon Sep 17 00:00:00 2001 From: Ske Date: Mon, 2 Dec 2019 16:49:39 +0100 Subject: [PATCH] Fix bounds checks and normalise nulls in API --- PluralKit.API/Controllers/MemberController.cs | 10 +++++----- PluralKit.API/Controllers/SystemController.cs | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/PluralKit.API/Controllers/MemberController.cs b/PluralKit.API/Controllers/MemberController.cs index 71247404..73f44c78 100644 --- a/PluralKit.API/Controllers/MemberController.cs +++ b/PluralKit.API/Controllers/MemberController.cs @@ -101,12 +101,12 @@ namespace PluralKit.API.Controllers return BadRequest(); member.Name = newMember.Name; - member.DisplayName = newMember.DisplayName; - member.Color = newMember.Color; - member.AvatarUrl = newMember.AvatarUrl; + member.DisplayName = newMember.DisplayName.NullIfEmpty(); + member.Color = newMember.Color.NullIfEmpty(); + member.AvatarUrl = newMember.AvatarUrl.NullIfEmpty(); member.Birthday = newMember.Birthday; - member.Pronouns = newMember.Pronouns; - member.Description = newMember.Description; + member.Pronouns = newMember.Pronouns.NullIfEmpty(); + member.Description = newMember.Description.NullIfEmpty(); member.ProxyTags = newMember.ProxyTags; member.KeepProxy = newMember.KeepProxy; await _data.SaveMember(member); diff --git a/PluralKit.API/Controllers/SystemController.cs b/PluralKit.API/Controllers/SystemController.cs index 1503c3fa..ce43700a 100644 --- a/PluralKit.API/Controllers/SystemController.cs +++ b/PluralKit.API/Controllers/SystemController.cs @@ -113,17 +113,17 @@ namespace PluralKit.API.Controllers var system = _auth.CurrentSystem; // Bounds checks - if (newSystem.Name.Length > Limits.MaxSystemNameLength) + if (newSystem.Name != null && newSystem.Name.Length > Limits.MaxSystemNameLength) return BadRequest($"System name too long ({newSystem.Name.Length} > {Limits.MaxSystemNameLength}."); - if (newSystem.Tag.Length > Limits.MaxSystemTagLength) + if (newSystem.Tag != null && newSystem.Tag.Length > Limits.MaxSystemTagLength) return BadRequest($"System tag too long ({newSystem.Tag.Length} > {Limits.MaxSystemTagLength}."); - if (newSystem.Description.Length > Limits.MaxDescriptionLength) + if (newSystem.Description != null && newSystem.Description.Length > Limits.MaxDescriptionLength) return BadRequest($"System description too long ({newSystem.Description.Length} > {Limits.MaxDescriptionLength}."); - system.Name = newSystem.Name; - system.Description = newSystem.Description; - system.Tag = newSystem.Tag; - system.AvatarUrl = newSystem.AvatarUrl; + system.Name = newSystem.Name.NullIfEmpty(); + system.Description = newSystem.Description.NullIfEmpty(); + system.Tag = newSystem.Tag.NullIfEmpty(); + system.AvatarUrl = newSystem.AvatarUrl.NullIfEmpty(); system.UiTz = newSystem.UiTz ?? "UTC"; await _data.SaveSystem(system);