Trim user input so stuff doesn't break

This commit is contained in:
RisaDev
2024-03-03 01:50:48 +03:00
parent c8e38eb9eb
commit 7f18030018
5 changed files with 12 additions and 3 deletions

View File

@@ -16,6 +16,9 @@ internal static class StringExtensions
#if !INCOGNIFY_STRINGS #if !INCOGNIFY_STRINGS
return str; return str;
#endif #endif
str = str.Trim();
if (str.Contains(" ")) if (str.Contains(" "))
{ {
var split = str.Split(' '); var split = str.Split(' ');

View File

@@ -145,8 +145,8 @@ public sealed class Profile : ISavable
{ {
CreationDate = creationDate, CreationDate = creationDate,
UniqueId = obj["UniqueId"]?.ToObject<Guid>() ?? throw new ArgumentNullException("UniqueId"), UniqueId = obj["UniqueId"]?.ToObject<Guid>() ?? throw new ArgumentNullException("UniqueId"),
Name = new LowerString(obj["Name"]?.ToObject<string>() ?? throw new ArgumentNullException("Name")), Name = new LowerString(obj["Name"]?.ToObject<string>()?.Trim() ?? throw new ArgumentNullException("Name")),
CharacterName = new LowerString(obj["CharacterName"]?.ToObject<string>() ?? throw new ArgumentNullException("CharacterName")), CharacterName = new LowerString(obj["CharacterName"]?.ToObject<string>()?.Trim() ?? throw new ArgumentNullException("CharacterName")),
LimitLookupToOwnedObjects = obj["LimitLookupToOwnedObjects"]?.ToObject<bool>() ?? throw new ArgumentNullException("LimitLookupToOwnedObjects"), LimitLookupToOwnedObjects = obj["LimitLookupToOwnedObjects"]?.ToObject<bool>() ?? throw new ArgumentNullException("LimitLookupToOwnedObjects"),
Enabled = obj["Enabled"]?.ToObject<bool>() ?? throw new ArgumentNullException("Enabled"), Enabled = obj["Enabled"]?.ToObject<bool>() ?? throw new ArgumentNullException("Enabled"),
ModifiedDate = obj["ModifiedDate"]?.ToObject<DateTimeOffset>() ?? creationDate, ModifiedDate = obj["ModifiedDate"]?.ToObject<DateTimeOffset>() ?? creationDate,

View File

@@ -199,6 +199,8 @@ public class ProfileManager : IDisposable
/// </summary> /// </summary>
public void Rename(Profile profile, string newName) public void Rename(Profile profile, string newName)
{ {
newName = newName.Trim();
var oldName = profile.Name.Text; var oldName = profile.Name.Text;
if (oldName == newName) if (oldName == newName)
return; return;
@@ -216,6 +218,8 @@ public class ProfileManager : IDisposable
/// </summary> /// </summary>
public void ChangeCharacterName(Profile profile, string newName) public void ChangeCharacterName(Profile profile, string newName)
{ {
newName = newName.Trim();
var oldName = profile.CharacterName.Text; var oldName = profile.CharacterName.Text;
if (oldName == newName) if (oldName == newName)
return; return;

View File

@@ -93,7 +93,7 @@ public sealed class Template : ISavable
{ {
CreationDate = creationDate, CreationDate = creationDate,
UniqueId = obj["UniqueId"]?.ToObject<Guid>() ?? throw new ArgumentNullException("UniqueId"), UniqueId = obj["UniqueId"]?.ToObject<Guid>() ?? throw new ArgumentNullException("UniqueId"),
Name = new LowerString(obj["Name"]?.ToObject<string>() ?? throw new ArgumentNullException("Name")), Name = new LowerString(obj["Name"]?.ToObject<string>()?.Trim() ?? throw new ArgumentNullException("Name")),
ModifiedDate = obj["ModifiedDate"]?.ToObject<DateTimeOffset>() ?? creationDate, ModifiedDate = obj["ModifiedDate"]?.ToObject<DateTimeOffset>() ?? creationDate,
Bones = obj["Bones"]?.ToObject<Dictionary<string, BoneTransform>>() ?? throw new ArgumentNullException("Bones"), Bones = obj["Bones"]?.ToObject<Dictionary<string, BoneTransform>>() ?? throw new ArgumentNullException("Bones"),
IsWriteProtected = obj["IsWriteProtected"]?.ToObject<bool>() ?? false IsWriteProtected = obj["IsWriteProtected"]?.ToObject<bool>() ?? false

View File

@@ -141,6 +141,8 @@ public class TemplateManager
/// </summary> /// </summary>
public void Rename(Template template, string newName) public void Rename(Template template, string newName)
{ {
newName = newName.Trim();
var oldName = template.Name.Text; var oldName = template.Name.Text;
if (oldName == newName) if (oldName == newName)
return; return;