From ac193b4e47f7eedf0fcb06b2eccc53a7544f5fce Mon Sep 17 00:00:00 2001 From: Velvet <42438262+VelvetToroyashi@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:12:38 -0400 Subject: [PATCH 1/2] fix(extensions): Flush the writer before deserializing Flushes the writer, which forces it to commit to the backing store - in the case of small JSON payloads, this causes an edge-case bug wherein the writer hasn't written anything, and thus this method will attempt to deserialize nothing, which throws an exception. --- Remora.Rest/Extensions/JsonExtensions.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Remora.Rest/Extensions/JsonExtensions.cs b/Remora.Rest/Extensions/JsonExtensions.cs index df260cf..9c3b58f 100644 --- a/Remora.Rest/Extensions/JsonExtensions.cs +++ b/Remora.Rest/Extensions/JsonExtensions.cs @@ -34,6 +34,8 @@ public static class JsonExtensions using var writer = new Utf8JsonWriter(bufferWriter); element.WriteTo(writer); + element.Flush(); + return JsonSerializer.Deserialize(bufferWriter.WrittenSpan, options); } From 42b15c36ee7c99042caa3988aea0862ac6099279 Mon Sep 17 00:00:00 2001 From: Velvet <42438262+VelvetToroyashi@users.noreply.github.com> Date: Wed, 7 Aug 2024 21:17:51 +0000 Subject: [PATCH 2/2] fix: Flush the writer, not the element --- Remora.Rest/Extensions/JsonExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Remora.Rest/Extensions/JsonExtensions.cs b/Remora.Rest/Extensions/JsonExtensions.cs index 9c3b58f..20fa74b 100644 --- a/Remora.Rest/Extensions/JsonExtensions.cs +++ b/Remora.Rest/Extensions/JsonExtensions.cs @@ -34,7 +34,7 @@ public static class JsonExtensions using var writer = new Utf8JsonWriter(bufferWriter); element.WriteTo(writer); - element.Flush(); + writer.Flush(); return JsonSerializer.Deserialize(bufferWriter.WrittenSpan, options); }