Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using NUnit.Framework;
using System.Collections.Generic;
Expand Down Expand Up @@ -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\""));
}
}
}
9 changes: 8 additions & 1 deletion src/electionguard/serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <memory>
#include <nlohmann/json.hpp>
#include <unordered_map>
#include <regex>

using electionguard::G;
using electionguard::P;
Expand All @@ -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;
Expand Down Expand Up @@ -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<electionguard::Manifest> fromBson(vector<uint8_t> data)
Expand Down