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..e3be698 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,11 @@ namespace electionguard static string toJson(const electionguard::Manifest &serializable) { - return fromObject(serializable).dump(); + 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"); } static unique_ptr fromBson(vector data)