Fix bounds checks and normalise nulls in API

This commit is contained in:
Ske 2019-12-02 16:49:39 +01:00
parent 7db55a3992
commit 55f77df39e
2 changed files with 12 additions and 12 deletions

View File

@ -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);

View File

@ -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);