Election-Tech-Initiative / electionguard-cpp

A C++ implementation of ElectionGuard specification focused on encryption components.
https://www.electionguard.vote/
MIT License
23 stars 26 forks source link

🐞 Unicode gets double escaped when serializing to json #334

Closed lprichar closed 1 year ago

lprichar commented 1 year ago

Is there an existing issue for this?

Current Behavior

.ToJson() converts Ăș to \\u00f

Expected Behavior

.ToJson() should convert Ăș to \u00f

Steps To Reproduce

The following test should pass:

[Test]
public void Test_Unicode_CandidateNames()
{
    var candidateName = new Language("RaĂșl", "en");
    var candidate = new Candidate(
        "candidate-1",
        new InternationalizedText(new[] { candidateName }),
        string.Empty,
        string.Empty,
        false);

    List<Candidate> candidates = new List<Candidate>
    {
        candidate
    };

    var result = new Manifest(
        "test-manifest",
        ElectionType.general,
        DateTime.Now,
        DateTime.Now,
        new GeopoliticalUnit[] { },
        new Party[] { },
        candidates.ToArray(),
        new ContestDescription[] { },
        new BallotStyle[] { },
        new InternationalizedText(new Language[] { }),
        new ContactInformation("na"));

    var json = result.ToJson();
    Assert.IsTrue(json.Contains("\"value\":\"Ra\\u00fal\""));
}

Environment

- OS:

Anything else?

No response