CSharpSDK icon indicating copy to clipboard operation
CSharpSDK copied to clipboard

Fix for non-popular control characters not being escaped during JSON serialization

Open kornman00 opened this issue 4 years ago • 1 comments

Refer to https://datatracker.ietf.org/doc/html/rfc4627.html#section-2.5.

  • Extend EscapeCharacters to include the full \u0000 to \u001f range.

  • Add BuildEscapeTableArray() and use it to populate EscapeTable. This has the added benefit of removing the explicit .cctor, which should simplify JIT code, since it shouldn't be implicitly inserting preamble cctor calls in all class methods (assuming my low level knowledge here circa 2017 still applies today).

  • Modify SerializeString() to handle control characters that require \uXXXX.

  • Copypasta https://github.com/PlayFab/UnitySDK/blob/master/ExampleTestProject/Assets/Testing/Tests/Utility/JsonUnitTests.cs

  • Add new TestSimpleJsonSerializeStringWithEscapes to JsonUnitTests.cs for verifying non "popular control characters" are escaped via \uXXXX during SerializeString.

kornman00 avatar Oct 28 '21 20:10 kornman00

@toddbellMSFT, I leave this to you to test and land, since external PR's don't invoke automated tests. But the code itself looks good to me. 👍

pgilmorepf avatar Oct 28 '21 22:10 pgilmorepf

This change was accepted into the codebase earlier this year: https://github.com/PlayFab/CSharpSDK/commit/0df95be0f09cd156223a2cb1ff96fe1ab87f3815

toddbellMSFT avatar Dec 22 '22 21:12 toddbellMSFT