From 36f2d480e725c1dfd1ecb6bfd843484c9f1b7f44 Mon Sep 17 00:00:00 2001 From: Lee Richardson Date: Mon, 3 Oct 2022 09:08:17 -0400 Subject: [PATCH 1/2] Fix double slashes with single slashes in manifest json generation --- .../ElectionGuard.Encryption.Tests/TestManifest.cs | 3 ++- src/electionguard/serialize.hpp | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bindings/netstandard/ElectionGuard/ElectionGuard.Encryption.Tests/TestManifest.cs b/bindings/netstandard/ElectionGuard/ElectionGuard.Encryption.Tests/TestManifest.cs index 40d829e..f1ca44a 100644 --- a/bindings/netstandard/ElectionGuard/ElectionGuard.Encryption.Tests/TestManifest.cs +++ b/bindings/netstandard/ElectionGuard/ElectionGuard.Encryption.Tests/TestManifest.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using NUnit.Framework; using System.Collections.Generic; @@ -185,6 +185,7 @@ public void Test_Unicode_CandidateNames() var json = result.ToJson(); Assert.IsTrue(json.Contains("\"value\":\"Ra\\\\u00fal\"")); + Assert.IsTrue(json.Contains("\"value\":\"Ra\\u00fal\"")); } } } diff --git a/src/electionguard/serialize.hpp b/src/electionguard/serialize.hpp index 3f96141..3d6932a 100644 --- a/src/electionguard/serialize.hpp +++ b/src/electionguard/serialize.hpp @@ -16,6 +16,7 @@ #include #include #include +#include using electionguard::G; using electionguard::P; @@ -25,6 +26,8 @@ using nlohmann::json; using std::make_unique; using std::reference_wrapper; using std::string; +using std::regex; +using std::regex_replace; using std::to_string; using std::unique_ptr; using std::vector; @@ -581,7 +584,8 @@ namespace electionguard static string toJson(const electionguard::Manifest &serializable) { - return fromObject(serializable).dump(); + auto manifestStr = fromObject(serializable).dump(); + return regex_replace(manifestStr, regex("\\\\\\\\u"), "\\u"); } static unique_ptr fromBson(vector data) From dd01716e98b07f584d4aa91f3fe9822fd5839c5e Mon Sep 17 00:00:00 2001 From: Lee Richardson Date: Mon, 3 Oct 2022 09:15:34 -0400 Subject: [PATCH 2/2] better documentation --- src/electionguard/serialize.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/electionguard/serialize.hpp b/src/electionguard/serialize.hpp index 3d6932a..e3be698 100644 --- a/src/electionguard/serialize.hpp +++ b/src/electionguard/serialize.hpp @@ -585,6 +585,9 @@ namespace electionguard static string toJson(const electionguard::Manifest &serializable) { auto manifestStr = fromObject(serializable).dump(); + // special characters like ú are converted to ascii escapes in C# but then + // https://github.com/nlohmann/json has a bug where it duplicates slashes, + // so this code removes the duplicates to work around the bug return regex_replace(manifestStr, regex("\\\\\\\\u"), "\\u"); }