From de1de8fb742799d516057b9f57d95545748d1349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Sat, 7 Jan 2023 14:40:48 +0100 Subject: [PATCH] fix(packets): correctly handle nullables in NullableStringConverter --- .../Converters/NullableStringConverter.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Packets/NosSmooth.PacketSerializer/Converters/Special/Converters/NullableStringConverter.cs b/Packets/NosSmooth.PacketSerializer/Converters/Special/Converters/NullableStringConverter.cs index 22c6899..578e06b 100644 --- a/Packets/NosSmooth.PacketSerializer/Converters/Special/Converters/NullableStringConverter.cs +++ b/Packets/NosSmooth.PacketSerializer/Converters/Special/Converters/NullableStringConverter.cs @@ -51,13 +51,19 @@ public class NullableStringConverter : BaseStringConverter> return Result.FromError(nextToken); } - if (packetToken.Token.Length == 2 && packetToken.Token.StartsWith("-1")) - { - stringEnumerator.GetNextToken(out _); // seek. - return Result.FromSuccess(null); + if (options.CanBeNull) + { // even though this is nullable converter and it could be expected + // that only nullables will be passed, it's possible that + // due to easier management, a non nullable entity will be passed + // here. + if (packetToken.Token.Length == 2 && packetToken.Token.StartsWith("-1")) + { + stringEnumerator.GetNextToken(out _); // seek. + return Result.FromSuccess(null); + } } - var result = _stringSerializer.Deserialize(ref stringEnumerator, new DeserializeOptions(true)); + var result = _stringSerializer.Deserialize(ref stringEnumerator, options); if (!result.IsSuccess) { return Result.FromError(result); -- 2.49.0