Skip to content

Commit

Permalink
Trim user input so stuff doesn't break
Browse files Browse the repository at this point in the history
  • Loading branch information
RisaDev committed Mar 2, 2024
1 parent c8e38eb commit 7f18030
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CustomizePlus/Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public static string Incognify(this string str)
#if !INCOGNIFY_STRINGS
return str;
#endif

str = str.Trim();

if (str.Contains(" "))
{
var split = str.Split(' ');
Expand Down
4 changes: 2 additions & 2 deletions CustomizePlus/Profiles/Data/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ private static Profile LoadV4(TemplateManager templateManager, JObject obj)
{
CreationDate = creationDate,
UniqueId = obj["UniqueId"]?.ToObject<Guid>() ?? throw new ArgumentNullException("UniqueId"),
Name = new LowerString(obj["Name"]?.ToObject<string>() ?? throw new ArgumentNullException("Name")),
CharacterName = new LowerString(obj["CharacterName"]?.ToObject<string>() ?? throw new ArgumentNullException("CharacterName")),
Name = new LowerString(obj["Name"]?.ToObject<string>()?.Trim() ?? throw new ArgumentNullException("Name")),
CharacterName = new LowerString(obj["CharacterName"]?.ToObject<string>()?.Trim() ?? throw new ArgumentNullException("CharacterName")),
LimitLookupToOwnedObjects = obj["LimitLookupToOwnedObjects"]?.ToObject<bool>() ?? throw new ArgumentNullException("LimitLookupToOwnedObjects"),
Enabled = obj["Enabled"]?.ToObject<bool>() ?? throw new ArgumentNullException("Enabled"),
ModifiedDate = obj["ModifiedDate"]?.ToObject<DateTimeOffset>() ?? creationDate,
Expand Down
4 changes: 4 additions & 0 deletions CustomizePlus/Profiles/ProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ public Profile Clone(Profile clone, string name, bool handlePath)
/// </summary>
public void Rename(Profile profile, string newName)
{
newName = newName.Trim();

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

var oldName = profile.CharacterName.Text;
if (oldName == newName)
return;
Expand Down
2 changes: 1 addition & 1 deletion CustomizePlus/Templates/Data/Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static Template LoadV4(JObject obj)
{
CreationDate = creationDate,
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,
Bones = obj["Bones"]?.ToObject<Dictionary<string, BoneTransform>>() ?? throw new ArgumentNullException("Bones"),
IsWriteProtected = obj["IsWriteProtected"]?.ToObject<bool>() ?? false
Expand Down
2 changes: 2 additions & 0 deletions CustomizePlus/Templates/TemplateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public Template Clone(Template clone, string name, bool handlePath)
/// </summary>
public void Rename(Template template, string newName)
{
newName = newName.Trim();

var oldName = template.Name.Text;
if (oldName == newName)
return;
Expand Down

0 comments on commit 7f18030

Please sign in to comment.