From 055cd0bf34464712d6c10bc8213a2f7ccc8589fd Mon Sep 17 00:00:00 2001 From: Alex Bespalov Date: Tue, 29 Oct 2024 13:40:53 +0200 Subject: [PATCH 1/3] Fix plus serialization via `TextEncoderSettings` --- .../Nethermind.Serialization.Json/EthereumJsonSerializer.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs b/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs index a99afd49a63..68cb276ed45 100644 --- a/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs +++ b/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs @@ -6,8 +6,10 @@ using System.Collections.Generic; using System.IO; using System.IO.Pipelines; +using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Json.Serialization; +using System.Text.Unicode; using System.Threading.Tasks; using Nethermind.Core.Collections; @@ -54,6 +56,9 @@ public string Serialize(T value, bool indented = false) private static JsonSerializerOptions CreateOptions(bool indented, IEnumerable converters = null, int maxDepth = 64) { + var encoderSettings = new TextEncoderSettings(UnicodeRanges.BasicLatin); + encoderSettings.AllowCharacter('+'); + var options = new JsonSerializerOptions { WriteIndented = indented, @@ -63,6 +68,7 @@ private static JsonSerializerOptions CreateOptions(bool indented, IEnumerable Date: Tue, 29 Oct 2024 13:41:20 +0200 Subject: [PATCH 2/3] Use `UnsafeRelaxedJsonEscaping` --- .../Nethermind.Serialization.Json/EthereumJsonSerializer.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs b/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs index 68cb276ed45..01e23bfccf6 100644 --- a/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs +++ b/src/Nethermind/Nethermind.Serialization.Json/EthereumJsonSerializer.cs @@ -56,9 +56,6 @@ public string Serialize(T value, bool indented = false) private static JsonSerializerOptions CreateOptions(bool indented, IEnumerable converters = null, int maxDepth = 64) { - var encoderSettings = new TextEncoderSettings(UnicodeRanges.BasicLatin); - encoderSettings.AllowCharacter('+'); - var options = new JsonSerializerOptions { WriteIndented = indented, @@ -68,7 +65,7 @@ private static JsonSerializerOptions CreateOptions(bool indented, IEnumerable Date: Tue, 29 Oct 2024 13:45:38 +0200 Subject: [PATCH 3/3] Update tests --- .../Nethermind.JsonRpc.Test/Data/SerializationTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Data/SerializationTestBase.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Data/SerializationTestBase.cs index 9481c0e77d7..af8d325612c 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Data/SerializationTestBase.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Data/SerializationTestBase.cs @@ -69,7 +69,7 @@ protected void TestToJson(T item, string expectedResult, params JsonConverter IJsonSerializer serializer = BuildSerializer(converters); string result = serializer.Serialize(item); - Assert.That(result, Is.EqualTo(expectedResult.Replace("+", "\\u002B")), result.Replace("\"", "\\\"")); + Assert.That(result, Is.EqualTo(expectedResult), result.Replace("\"", "\\\"")); } private static IJsonSerializer BuildSerializer(params JsonConverter[] converters) => new EthereumJsonSerializer(converters);