From 86458129b541445821323e7afb645aa751025ea2 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 30 Nov 2022 18:01:45 +0000 Subject: [PATCH] Explicit Ordinal string comparison --- .../src/Internal/ValueConverters/StringToEnumConverter.cs | 8 +++++--- VpSharp/src/VirtualParadiseClient.Worlds.cs | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/VpSharp/src/Internal/ValueConverters/StringToEnumConverter.cs b/VpSharp/src/Internal/ValueConverters/StringToEnumConverter.cs index e5563e5..13d44c1 100644 --- a/VpSharp/src/Internal/ValueConverters/StringToEnumConverter.cs +++ b/VpSharp/src/Internal/ValueConverters/StringToEnumConverter.cs @@ -1,4 +1,4 @@ -using System.Reflection; +using System.Reflection; using VpSharp.Internal.Attributes; namespace VpSharp.Internal.ValueConverters; @@ -12,8 +12,10 @@ internal sealed class StringToEnumConverter : ValueConverter public override void Deserialize(TextReader reader, out T result) { string value = reader.ReadToEnd(); - - FieldInfo? field = typeof(T).GetFields().FirstOrDefault(f => string.Equals(f.GetCustomAttribute()?.Key, value)); + + FieldInfo? field = typeof(T).GetFields().FirstOrDefault(f => + string.Equals(f.GetCustomAttribute()?.Key, value, StringComparison.Ordinal)); + if (field is not null) { result = (T)field.GetValue(Enum.GetValues()[0])!; diff --git a/VpSharp/src/VirtualParadiseClient.Worlds.cs b/VpSharp/src/VirtualParadiseClient.Worlds.cs index 4525156..d8ebee4 100644 --- a/VpSharp/src/VirtualParadiseClient.Worlds.cs +++ b/VpSharp/src/VirtualParadiseClient.Worlds.cs @@ -1,4 +1,4 @@ -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Threading.Channels; using VpSharp.Entities; @@ -30,7 +30,7 @@ public sealed partial class VirtualParadiseClient await foreach (VirtualParadiseWorld world in EnumerateWorldsAsync()) { - if (string.Equals(world.Name, name)) + if (string.Equals(world.Name, name, StringComparison.Ordinal)) { return world; }