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(); return BadRequest();
member.Name = newMember.Name; member.Name = newMember.Name;
member.DisplayName = newMember.DisplayName; member.DisplayName = newMember.DisplayName.NullIfEmpty();
member.Color = newMember.Color; member.Color = newMember.Color.NullIfEmpty();
member.AvatarUrl = newMember.AvatarUrl; member.AvatarUrl = newMember.AvatarUrl.NullIfEmpty();
member.Birthday = newMember.Birthday; member.Birthday = newMember.Birthday;
member.Pronouns = newMember.Pronouns; member.Pronouns = newMember.Pronouns.NullIfEmpty();
member.Description = newMember.Description; member.Description = newMember.Description.NullIfEmpty();
member.ProxyTags = newMember.ProxyTags; member.ProxyTags = newMember.ProxyTags;
member.KeepProxy = newMember.KeepProxy; member.KeepProxy = newMember.KeepProxy;
await _data.SaveMember(member); await _data.SaveMember(member);

View File

@ -113,17 +113,17 @@ namespace PluralKit.API.Controllers
var system = _auth.CurrentSystem; var system = _auth.CurrentSystem;
// Bounds checks // 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}."); 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}."); 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}."); return BadRequest($"System description too long ({newSystem.Description.Length} > {Limits.MaxDescriptionLength}.");
system.Name = newSystem.Name; system.Name = newSystem.Name.NullIfEmpty();
system.Description = newSystem.Description; system.Description = newSystem.Description.NullIfEmpty();
system.Tag = newSystem.Tag; system.Tag = newSystem.Tag.NullIfEmpty();
system.AvatarUrl = newSystem.AvatarUrl; system.AvatarUrl = newSystem.AvatarUrl.NullIfEmpty();
system.UiTz = newSystem.UiTz ?? "UTC"; system.UiTz = newSystem.UiTz ?? "UTC";
await _data.SaveSystem(system); await _data.SaveSystem(system);